chengjiaoChart2.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <view class="content">
  3. <!-- #ifdef APP-PLUS || H5 -->
  4. <view class="title"
  5. :style="`background-color: ${themeColor50};`">
  6. {{title}}
  7. </view>
  8. <view class="count">
  9. {{count}}
  10. </view>
  11. <view :prop="option" :change:prop="echarts.updateEcharts" id="chengjiaoChart2" class="echarts" v-show="fuzhuColor50!=null && dataList.length > 0"></view>
  12. <!-- #endif -->
  13. <!-- #ifndef APP-PLUS || H5 -->
  14. <view>非 APP、H5 环境不支持</view>
  15. <!-- #endif -->
  16. </view>
  17. </template>
  18. <script>
  19. import echarts from '../../../static/echarts.js'
  20. export default {
  21. props: {
  22. title: String,
  23. count: Number,
  24. dataList: {
  25. type: Array,
  26. default: () => {
  27. return []
  28. }
  29. },
  30. dataList1: {
  31. type: Array,
  32. default: () => {
  33. return []
  34. }
  35. },
  36. themeColor50: String,
  37. fuzhuColor50: String,
  38. },
  39. data() {
  40. return {
  41. option: {
  42. grid: {
  43. left: '10%',
  44. right: '10%',
  45. top: '0%',
  46. bottom: '10%',
  47. containLabel: false
  48. },
  49. xAxis: {
  50. show: false,
  51. type: 'category',
  52. boundaryGap: ['20%', '20%']
  53. },
  54. yAxis: {
  55. show: false,
  56. type: 'value',
  57. boundaryGap: ['70%', '70%']
  58. },
  59. series: [
  60. {
  61. type: 'line',
  62. smooth: 0.5,
  63. symbol: 'none',
  64. lineStyle: {
  65. color: null,
  66. width: 3
  67. },
  68. data: []
  69. },
  70. {
  71. type: 'line',
  72. smooth: 0.5,
  73. symbol: 'none',
  74. lineStyle: {
  75. color: null,
  76. width: 3
  77. },
  78. data: []
  79. }
  80. ]
  81. }
  82. }
  83. },
  84. created() {
  85. // this.option.series[0].data = []
  86. },
  87. methods: {
  88. getDataAction() {
  89. this.option.series[0].data = this.dataList
  90. this.option.series[1].data = this.dataList1
  91. this.option.series[0].lineStyle.color = this.themeColor50
  92. this.option.series[1].lineStyle.color = this.fuzhuColor50
  93. // console.log('成交2数据刷新', this.option.series)
  94. },
  95. },
  96. watch: {
  97. dataList: {
  98. handler(e1, e2) {
  99. var e1Str = JSON.stringify(e1)
  100. var e2Str = JSON.stringify(e2)
  101. if (e1Str && e1Str != e2Str) {
  102. this.getDataAction()
  103. }
  104. },
  105. deep: true,
  106. immediate: true
  107. },
  108. dataList1: {
  109. handler(e) {
  110. this.getDataAction()
  111. },
  112. deep: true,
  113. immediate: true
  114. },
  115. themeColor50: {
  116. handler(e) {
  117. if (e) {
  118. this.option.series[0].lineStyle.color = this.themeColor50
  119. }
  120. },
  121. immediate: true
  122. },
  123. fuzhuColor50: {
  124. handler(e) {
  125. if (e) {
  126. this.option.series[1].lineStyle.color = this.fuzhuColor50
  127. }
  128. },
  129. immediate: true
  130. }
  131. }
  132. }
  133. </script>
  134. <script module="echarts" lang="renderjs">
  135. let myChart
  136. export default {
  137. mounted() {
  138. this.initAction()
  139. },
  140. methods: {
  141. initAction() {
  142. if (typeof window.echarts === 'function') {
  143. this.initEcharts()
  144. } else {
  145. // 动态引入较大类库避免影响页面展示
  146. const script = document.createElement('script')
  147. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  148. script.src = 'static/echarts.js'
  149. script.onload = this.initEcharts.bind(this)
  150. document.head.appendChild(script)
  151. }
  152. },
  153. initEcharts() {
  154. myChart = echarts.init(document.getElementById("chengjiaoChart2"))
  155. // 观测更新的数据在 view 层可以直接访问到
  156. myChart.setOption(this.option)
  157. },
  158. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  159. if (myChart) {
  160. // 监听 service 层数据变更
  161. myChart.setOption(newValue)
  162. }
  163. else {
  164. // console.log("无chart11111 -> this.$refs", this.$refs.chartId.$el.id)
  165. this.initAction()
  166. }
  167. },
  168. onClick(event, ownerInstance) {
  169. // 调用 service 层的方法
  170. ownerInstance.callMethod('onViewClick', {
  171. test: 'test'
  172. })
  173. }
  174. }
  175. }
  176. </script>
  177. <style>
  178. .content {
  179. width: 100%;
  180. height: 100%;
  181. }
  182. .title {
  183. font-size: 32rpx;
  184. font-family: Verdana;
  185. text-align: center;
  186. width: 176rpx;
  187. margin-left: calc((100% - 176rpx) / 2);
  188. line-height: 46rpx;
  189. /* background-color: #E1F4F4; */
  190. color: rgba(0, 0, 0, 0.65);
  191. margin-top: 28rpx;
  192. margin-left: 20rpx;
  193. border-radius: 8rpx;
  194. }
  195. .count {
  196. width: 100%;
  197. margin-top: 24rpx;
  198. height: 48rpx;
  199. line-height: 48rpx;
  200. text-align: center;
  201. font-family: Verdana;
  202. font-size: 40rpx;
  203. color: rgba(32, 38, 56, 1);
  204. }
  205. .echarts {
  206. margin-top: 10rpx;
  207. width: 100%;
  208. height: 80rpx;
  209. }
  210. </style>