liquidChart.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. axisPointer: {
  41. type: 'cross',
  42. animation: false,
  43. label: {
  44. backgroundColor: '#505765'
  45. }
  46. }
  47. },
  48. grid: {
  49. left: '7%',
  50. right: '15%',
  51. bottom: '15%',
  52. containLabel: true
  53. },
  54. toolbox: {
  55. // feature: {
  56. // saveAsImage: {}
  57. // }
  58. },
  59. legend: {
  60. data: ['水压/水位(兆帕/米)', '电量/信号(%)'],
  61. // left: 10
  62. },
  63. xAxis: {
  64. type: 'category',
  65. axisTick: {
  66. alignWithLabel: true
  67. },
  68. data:this.bindData.stiem.map( function(value,index){
  69. return `${value.substring(0,10)}\n${value.substring(11,20)}`
  70. })
  71. },
  72. yAxis: [{
  73. name: '液位',
  74. type: 'value',
  75. // max: 1
  76. },
  77. ],
  78. series: [{
  79. name: tes2,
  80. type: 'line',
  81. stack: 'Pa',
  82. animation: false,
  83. data:this.bindData.water_data,
  84. color: ['#2699fb'],
  85. yAxisIndex: 0
  86. },
  87. ]
  88. }
  89. }
  90. },
  91. onLoad() {
  92. },
  93. methods: {
  94. changeOption() {
  95. const data = this.option.series[0].data
  96. // 随机更新示例数据
  97. data.forEach((item, index) => {
  98. data.splice(index, 1, Math.random() * 40)
  99. })
  100. },
  101. onViewClick(options) {
  102. console.log(options)
  103. }
  104. }
  105. }
  106. </script>
  107. <script module="echarts" lang="renderjs">
  108. let myChart
  109. export default {
  110. mounted() {
  111. console.log('this.bindData')
  112. console.log(this.bindData)
  113. if (typeof window.echarts === 'function') {
  114. this.initEcharts()
  115. } else {
  116. // 动态引入较大类库避免影响页面展示
  117. const script = document.createElement('script')
  118. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  119. script.src = 'static/echarts.min.js'
  120. script.onload = this.initEcharts.bind(this)
  121. document.head.appendChild(script)
  122. }
  123. },
  124. methods: {
  125. initEcharts() {
  126. myChart = echarts.init(document.getElementById('echarts2'))
  127. // 观测更新的数据在 view 层可以直接访问到
  128. myChart.setOption(this.option)
  129. },
  130. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  131. // 监听 service 层数据变更
  132. myChart.setOption(newValue)
  133. },
  134. onClick(event, ownerInstance) {
  135. // 调用 service 层的方法
  136. ownerInstance.callMethod('onViewClick', {
  137. test: 'test'
  138. })
  139. }
  140. }
  141. }
  142. </script>
  143. <style>
  144. .content {
  145. display: flex;
  146. flex-direction: column;
  147. align-items: center;
  148. justify-content: center;
  149. }
  150. .echarts {
  151. width: 100%;
  152. height: 500rpx;
  153. margin-bottom: 70rpx;
  154. }
  155. </style>