chart2.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view class="content">
  3. <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts2"
  4. class="echarts"></view>
  5. </view>
  6. </template>
  7. <script>
  8. var dwtype = "2";
  9. var tes = '0';
  10. var tes2 = '';
  11. var tyss = "";
  12. if (dwtype == 2) {
  13. tes = '一周设备数值变化';
  14. tes2 = '水压值';
  15. tyss = "兆帕";
  16. }
  17. if (dwtype == 5) {
  18. tes = '一周水位值变化 (m)';
  19. tes2 = '水位值';
  20. tyss = "米";
  21. document.getElementById('dev_title_lab').innerHTML = '当前水位:';
  22. document.getElementById('dev_title_unit').innerHTML = 'm';
  23. }
  24. export default {
  25. props: {
  26. bindData: {
  27. type: Object,
  28. default: ''
  29. }
  30. },
  31. data() {
  32. return {
  33. option: {
  34. title: {
  35. x: 'center',
  36. text: tes
  37. },
  38. // tooltip: {
  39. // trigger: 'axis',
  40. // formatter:'{b}<br>{a} : {c} '+tyss+'<br>电量:{a} : {c}'
  41. // },
  42. tooltip: {
  43. trigger: 'axis',
  44. axisPointer: {
  45. type: 'cross',
  46. animation: false,
  47. label: {
  48. backgroundColor: '#505765'
  49. }
  50. }
  51. },
  52. grid: {
  53. left: '3%',
  54. right: '4%',
  55. bottom: '3%',
  56. containLabel: true
  57. },
  58. toolbox: {
  59. // feature: {
  60. // saveAsImage: {}
  61. // }
  62. },
  63. legend: {
  64. data: ['水压/水位(兆帕/米)', '电量/信号(%)'],
  65. left: 10
  66. },
  67. xAxis: {
  68. type: 'category',
  69. // boundaryGap: false,
  70. axisTick: {
  71. alignWithLabel: true
  72. },
  73. data: ["2021-06-11 12:48:19", "2021-06-11 12:18:17", "2021-06-11 11:48:17", "2021-06-11 11:18:17",
  74. "2021-06-11 10:48:17", "2021-06-11 10:18:17", "2021-06-11 09:48:17", "2021-06-11 09:18:19",
  75. "2021-06-11 08:48:19", "2021-06-11 08:18:19", "2021-06-11 07:48:17", "2021-06-11 07:18:17",
  76. "2021-06-11 06:48:17", "2021-06-11 06:18:18", "2021-06-11 05:48:17", "2021-06-11 05:18:18",
  77. "2021-06-11 04:48:19", "2021-06-11 04:18:17", "2021-06-11 03:48:17", "2021-06-11 03:18:17",
  78. "2021-06-11 02:48:17", "2021-06-11 02:18:17", "2021-06-11 01:48:17", "2021-06-11 01:18:24",
  79. "2021-06-11 00:48:17", "2021-06-11 00:18:16", "2021-06-10 23:48:17", "2021-06-10 23:18:17",
  80. "2021-06-10 22:48:21", "2021-06-10 22:18:19", "2021-06-10 21:48:17", "2021-06-10 21:18:21",
  81. "2021-06-10 20:48:17", "2021-06-10 20:18:16", "2021-06-10 19:48:17", "2021-06-10 19:18:16",
  82. "2021-06-10 18:48:17", "2021-06-10 18:18:17", "2021-06-10 17:48:19", "2021-06-10 17:18:19",
  83. "2021-06-10 16:48:19", "2021-06-10 16:18:17", "2021-06-10 15:48:18", "2021-06-10 15:18:16",
  84. "2021-06-10 14:48:16", "2021-06-10 14:18:17", "2021-06-10 13:48:16", "2021-06-10 13:18:18",
  85. "2021-06-10 12:48:17", "2021-06-10 12:18:16", "2021-06-10 11:48:16", "2021-06-10 11:18:16",
  86. "2021-06-10 10:48:16", "2021-06-10 10:18:18", "2021-06-10 09:48:16", "2021-06-10 09:18:17",
  87. "2021-06-10 08:48:18", "2021-06-10 08:18:16", "2021-06-10 07:48:18", "2021-06-10 07:18:16",
  88. "2021-06-10 06:48:16", "2021-06-10 06:18:16", "2021-06-10 05:48:16", "2021-06-10 05:18:16",
  89. "2021-06-10 04:48:18", "2021-06-10 04:18:16", "2021-06-10 03:48:18", "2021-06-10 03:18:18",
  90. "2021-06-10 02:48:18", "2021-06-10 02:18:16", "2021-06-10 01:48:18", "2021-06-10 01:18:18",
  91. "2021-06-10 00:48:18", "2021-06-10 00:18:16", "2021-06-09 23:48:16", "2021-06-09 23:18:16",
  92. "2021-06-09 22:48:16", "2021-06-09 22:18:16", "2021-06-09 21:48:18", "2021-06-09 21:18:16",
  93. "2021-06-09 20:48:18", "2021-06-09 20:18:16", "2021-06-09 19:48:16", "2021-06-09 19:18:22",
  94. "2021-06-09 18:48:15", "2021-06-09 18:18:16", "2021-06-09 17:48:15", "2021-06-09 17:18:18",
  95. "2021-06-09 16:48:15", "2021-06-09 16:18:21", "2021-06-09 15:48:18", "2021-06-09 15:18:16",
  96. "2021-06-09 14:48:15", "2021-06-09 14:18:15", "2021-06-09 13:48:15", "2021-06-09 13:18:15",
  97. "2021-06-09 12:48:15", "2021-06-09 12:18:15", "2021-06-09 11:48:17", "2021-06-09 11:18:16",
  98. "2021-06-09 10:48:17", "2021-06-09 10:18:18", "2021-06-09 09:48:18", "2021-06-09 09:18:15",
  99. "2021-06-09 08:48:17", "2021-06-09 08:18:15", "2021-06-09 07:48:17", "2021-06-09 07:18:17",
  100. "2021-06-09 06:48:17", "2021-06-09 06:18:17", "2021-06-09 05:48:18", "2021-06-09 05:18:17",
  101. "2021-06-09 04:48:17", "2021-06-09 04:18:17", "2021-06-09 03:48:17", "2021-06-09 03:18:15",
  102. "2021-06-09 02:48:17", "2021-06-09 02:18:18", "2021-06-09 01:48:17", "2021-06-09 01:18:17",
  103. "2021-06-09 00:48:18", "2021-06-09 00:18:17", "2021-06-08 23:48:17", "2021-06-08 23:18:17",
  104. "2021-06-08 22:48:17", "2021-06-08 22:18:16", "2021-06-08 21:48:15", "2021-06-08 21:18:16",
  105. "2021-06-08 20:48:17", "2021-06-08 20:18:14", "2021-06-08 19:48:17", "2021-06-08 19:18:14",
  106. "2021-06-08 18:48:25", "2021-06-08 18:18:16", "2021-06-08 17:48:15", "2021-06-08 17:18:16",
  107. "2021-06-08 16:48:15", "2021-06-08 16:18:16", "2021-06-08 15:18:14", "2021-06-08 14:48:17",
  108. "2021-06-08 14:18:16", "2021-06-08 13:48:19", "2021-06-08 13:18:14", "2021-06-08 12:48:14",
  109. "2021-06-08 12:18:19", "2021-06-08 11:48:15", "2021-06-08 11:18:16", "2021-06-08 10:48:14",
  110. "2021-06-08 10:18:21", "2021-06-08 09:48:16", "2021-06-08 09:18:16", "2021-06-08 08:48:17",
  111. "2021-06-08 08:18:14", "2021-06-08 07:48:16", "2021-06-08 07:18:16", "2021-06-08 06:48:14",
  112. "2021-06-08 06:18:17", "2021-06-08 05:48:16", "2021-06-08 05:18:16", "2021-06-08 04:48:17",
  113. "2021-06-08 04:18:16", "2021-06-08 03:48:17", "2021-06-08 03:18:17", "2021-06-08 02:48:14",
  114. "2021-06-08 02:18:16", "2021-06-08 01:48:16", "2021-06-08 01:18:14", "2021-06-08 00:48:17",
  115. "2021-06-08 00:18:16", "2021-06-07 23:48:16", "2021-06-07 23:18:16", "2021-06-07 22:48:16",
  116. "2021-06-07 22:18:15", "2021-06-07 21:48:14", "2021-06-07 21:18:16", "2021-06-07 20:48:16",
  117. "2021-06-07 20:18:16", "2021-06-07 19:48:14", "2021-06-07 19:18:16", "2021-06-07 18:48:13",
  118. "2021-06-07 18:18:16", "2021-06-07 17:48:15", "2021-06-07 17:18:16", "2021-06-07 16:48:17",
  119. "2021-06-07 16:18:14", "2021-06-07 15:48:13", "2021-06-07 15:18:16", "2021-06-07 14:48:13",
  120. "2021-06-07 14:18:14", "2021-06-07 13:48:15", "2021-06-07 13:18:14", "2021-06-07 12:48:13",
  121. "2021-06-07 12:18:15", "2021-06-07 11:48:15", "2021-06-07 11:18:14", "2021-06-07 10:48:16",
  122. "2021-06-07 10:18:13", "2021-06-07 09:48:14", "2021-06-07 09:18:14", "2021-06-07 08:48:13",
  123. "2021-06-07 08:18:13", "2021-06-07 07:48:16", "2021-06-07 07:18:15", "2021-06-07 06:48:15",
  124. "2021-06-07 06:18:16", "2021-06-07 05:48:15", "2021-06-07 05:18:15", "2021-06-07 04:48:13",
  125. "2021-06-07 04:18:16", "2021-06-07 03:48:15", "2021-06-07 03:18:15", "2021-06-07 02:48:15",
  126. "2021-06-07 02:18:13", "2021-06-07 01:48:15", "2021-06-07 01:18:14", "2021-06-07 00:48:15",
  127. "2021-06-07 00:18:18", "2021-06-06 23:48:17", "2021-06-06 23:18:15", "2021-06-06 22:48:13",
  128. "2021-06-06 22:18:14", "2021-06-06 21:48:22", "2021-06-06 21:18:18", "2021-06-06 20:48:13",
  129. "2021-06-06 20:18:15", "2021-06-06 19:48:16", "2021-06-06 19:18:15", "2021-06-06 18:48:15",
  130. "2021-06-06 18:18:13", "2021-06-06 17:48:13", "2021-06-06 17:18:16", "2021-06-06 16:48:13",
  131. "2021-06-06 16:18:12", "2021-06-06 15:48:13", "2021-06-06 15:18:12", "2021-06-06 14:48:15",
  132. "2021-06-06 14:18:17", "2021-06-06 13:48:14", "2021-06-06 13:18:18", "2021-06-06 12:48:14",
  133. "2021-06-06 12:18:12", "2021-06-06 11:48:15", "2021-06-06 11:18:15", "2021-06-06 10:48:13",
  134. "2021-06-06 10:18:15", "2021-06-06 09:48:13", "2021-06-06 09:18:13", "2021-06-06 08:48:17",
  135. "2021-06-06 08:18:12", "2021-06-06 07:48:13", "2021-06-06 07:18:12", "2021-06-06 06:48:12",
  136. "2021-06-06 06:18:15", "2021-06-06 05:48:15", "2021-06-06 05:18:14", "2021-06-06 04:48:14",
  137. "2021-06-06 04:18:15", "2021-06-06 03:48:14", "2021-06-06 03:18:18", "2021-06-06 02:48:17",
  138. "2021-06-06 02:18:14", "2021-06-06 01:48:18", "2021-06-06 01:18:14", "2021-06-06 00:48:14",
  139. "2021-06-06 00:18:14", "2021-06-05 23:48:14", "2021-06-05 23:18:14", "2021-06-05 22:48:14",
  140. "2021-06-05 22:18:17", "2021-06-05 21:48:17", "2021-06-05 21:18:14", "2021-06-05 20:48:14",
  141. "2021-06-05 20:18:14", "2021-06-05 19:48:14", "2021-06-05 19:18:14", "2021-06-05 18:48:13",
  142. "2021-06-05 18:18:12", "2021-06-05 17:48:13", "2021-06-05 17:18:16", "2021-06-05 16:48:12",
  143. "2021-06-05 16:18:14", "2021-06-05 15:48:16", "2021-06-05 15:18:15", "2021-06-05 14:48:11",
  144. "2021-06-05 14:18:13", "2021-06-05 13:48:11", "2021-06-05 13:18:13", "2021-06-05 12:48:11",
  145. "2021-06-05 12:18:12", "2021-06-05 11:48:13", "2021-06-05 11:18:13", "2021-06-05 10:48:11",
  146. "2021-06-05 10:18:11", "2021-06-05 09:48:13", "2021-06-05 09:18:11", "2021-06-05 08:48:10",
  147. "2021-06-05 08:18:11", "2021-06-05 07:48:10", "2021-06-05 07:18:10", "2021-06-05 06:48:11",
  148. "2021-06-05 06:18:11", "2021-06-05 05:48:10", "2021-06-05 05:18:11", "2021-06-05 04:48:10",
  149. "2021-06-05 04:18:11", "2021-06-05 03:48:10", "2021-06-05 03:18:11", "2021-06-05 02:48:10",
  150. "2021-06-05 02:18:13", "2021-06-05 01:48:10", "2021-06-05 01:18:10", "2021-06-05 00:48:12",
  151. "2021-06-05 00:18:10", "2021-06-04 23:48:13", "2021-06-04 23:18:10", "2021-06-04 22:48:10",
  152. "2021-06-04 22:18:10", "2021-06-04 21:48:10", "2021-06-04 21:18:10", "2021-06-04 20:48:12",
  153. "2021-06-04 20:18:12", "2021-06-04 19:48:10", "2021-06-04 19:18:10", "2021-06-04 18:48:10",
  154. "2021-06-04 18:18:10", "2021-06-04 17:48:12", "2021-06-04 17:18:12", "2021-06-04 16:48:10",
  155. "2021-06-04 16:18:12", "2021-06-04 15:48:10", "2021-06-04 15:18:10", "2021-06-04 14:48:10",
  156. "2021-06-04 14:18:12", "2021-06-04 13:48:10", "2021-06-04 13:18:12"
  157. ]
  158. },
  159. yAxis: [{
  160. name: '水压/水位',
  161. type: 'value',
  162. max: 1
  163. }, {
  164. name: '电量/信号',
  165. nameLocation: 'start',
  166. max: 100,
  167. type: 'value',
  168. // inverse: true
  169. }],
  170. dataZoom: [{
  171. type: 'slider',
  172. xAxisIndex: 0,
  173. filterMode: 'empty',
  174. start: 0,
  175. end: 100
  176. }, {
  177. type: 'inside',
  178. xAxisIndex: 0,
  179. filterMode: 'empty',
  180. start: 0,
  181. end: 100
  182. }],
  183. series: [{
  184. name: tes2,
  185. type: 'line',
  186. stack: 'Pa',
  187. animation: false,
  188. data: ["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  189. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  190. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  191. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  192. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  193. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  194. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  195. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  196. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  197. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  198. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  199. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  200. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  201. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  202. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  203. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  204. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  205. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  206. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  207. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  208. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"
  209. ],
  210. color: ['#2699fb'],
  211. yAxisIndex: 0
  212. }, {
  213. name: "信号强度",
  214. type: 'line',
  215. stack: '%',
  216. animation: false,
  217. data: [40, 40, 60, 60, 60, 60, 40, 60, 60, 60, 60, 60, 40, 40, 40, 60, 40, 60, 60, 60, 40,
  218. 60, 60, 60, 40, 40, 60, 40, 60, 60, 60, 40, 40, 60, 40, 40, 60, 60, 60, 40, 40, 40,
  219. 60, 60, 40, 40, 40, 40, 60, 60, 60, 60, 60, 60, 40, 60, 60, 60, 40, 40, 60, 60, 60,
  220. 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 40, 60, 60, 60, 60, 40, 40, 40, 60,
  221. 60, 40, 40, 40, 60, 40, 60, 40, 60, 40, 60, 40, 60, 60, 60, 40, 60, 60, 60, 40, 40,
  222. 40, 40, 40, 40, 40, 60, 40, 40, 60, 40, 40, 60, 60, 40, 40, 60, 40, 40, 60, 40, 40,
  223. 40, 40, 60, 40, 40, 40, 40, 60, 60, 60, 60, 60, 60, 40, 40, 60, 60, 40, 40, 60, 60,
  224. 40, 40, 60, 60, 60, 60, 60, 40, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 40, 60, 60,
  225. 60, 60, 60, 40, 60, 60, 40, 60, 40, 60, 60, 60, 40, 40, 40, 40, 60, 40, 40, 40, 60,
  226. 60, 40, 40, 40, 60, 60, 60, 60, 40, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
  227. 60, 60, 60, 40, 60, 60, 40, 60, 60, 60, 60, 40, 60, 60, 40, 60, 60, 60, 60, 60, 60,
  228. 60, 60, 60, 60, 60, 40, 60, 40, 40, 60, 60, 60, 60, 60, 60, 60, 40, 40, 60, 60, 60,
  229. 60, 60, 60, 60, 60, 60, 40, 60, 60, 40, 60, 60, 60, 60, 40, 60, 40, 60, 60, 60, 60,
  230. 60, 40, 60, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 60, 40, 60, 40, 40, 40, 60, 40,
  231. 60, 60, 60, 60, 40, 60, 60, 40, 60, 60, 60, 60, 60, 40, 60, 40, 60, 60, 60, 60, 60,
  232. 60, 60, 60, 60, 60, 60, 60, 40, 40, 40, 40, 40, 40, 40, 40, 40, 60, 40, 60, 40
  233. ],
  234. color: ['#ffff00'],
  235. yAxisIndex: 1
  236. }, {
  237. name: "电池电量",
  238. type: 'line',
  239. stack: 'a',
  240. animation: false,
  241. data: ["0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  242. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  243. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  244. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  245. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  246. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  247. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  248. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  249. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  250. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  251. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  252. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  253. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  254. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  255. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  256. "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
  257. "0", "0", "0", "0", "2", "3", "4", "5", "5", "6", "6", "6", "8", "8", "8", "9",
  258. "10", "10", "10", "9", "8", "9", "9", "10", "11", "12", "10", "11", "11", "12",
  259. "11", "11", "12", "13", "12", "12", "12", "12", "12", "12", "12", "11", "11", "10",
  260. "11", "11", "9", "10", "11", "10", "10", "11", "10", "10", "11", "11", "11", "11",
  261. "11", "11", "10", "10", "10", "10", "11", "9", "10", "9", "9", "10", "10", "10",
  262. "10", "10", "9", "10", "9", "11"
  263. ],
  264. color: ['#ff0000'],
  265. yAxisIndex: 1
  266. }]
  267. }
  268. }
  269. },
  270. onLoad() {
  271. },
  272. methods: {
  273. changeOption() {
  274. const data = this.option.series[0].data
  275. // 随机更新示例数据
  276. data.forEach((item, index) => {
  277. data.splice(index, 1, Math.random() * 40)
  278. })
  279. },
  280. onViewClick(options) {
  281. console.log(options)
  282. }
  283. }
  284. }
  285. </script>
  286. <script module="echarts" lang="renderjs">
  287. let myChart
  288. export default {
  289. mounted() {
  290. if (typeof window.echarts === 'function') {
  291. this.initEcharts()
  292. } else {
  293. // 动态引入较大类库避免影响页面展示
  294. const script = document.createElement('script')
  295. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  296. script.src = 'static/echarts.min.js'
  297. script.onload = this.initEcharts.bind(this)
  298. document.head.appendChild(script)
  299. }
  300. },
  301. methods: {
  302. initEcharts() {
  303. myChart = echarts.init(document.getElementById('echarts2'))
  304. // 观测更新的数据在 view 层可以直接访问到
  305. myChart.setOption(this.option)
  306. },
  307. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  308. // 监听 service 层数据变更
  309. myChart.setOption(newValue)
  310. },
  311. onClick(event, ownerInstance) {
  312. // 调用 service 层的方法
  313. ownerInstance.callMethod('onViewClick', {
  314. test: 'test'
  315. })
  316. }
  317. }
  318. }
  319. </script>
  320. <style>
  321. .content {
  322. display: flex;
  323. flex-direction: column;
  324. align-items: center;
  325. justify-content: center;
  326. }
  327. .echarts {
  328. width: 100%;
  329. height: 500rpx;
  330. margin-bottom: 70rpx;
  331. }
  332. </style>