From 2ccfcb5a17c31ade0b532d7cc77c9a65aed1343c Mon Sep 17 00:00:00 2001
From: chenzeping <ChenZeping02609@163.com>
Date: 星期一, 12 四月 2021 09:55:05 +0800
Subject: [PATCH] echarts实时数据

---
 src/components/BaseNav/PublicBounced/GasComponents/Echarts.vue |  216 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 157 insertions(+), 59 deletions(-)

diff --git a/src/components/BaseNav/PublicBounced/GasComponents/Echarts.vue b/src/components/BaseNav/PublicBounced/GasComponents/Echarts.vue
index 2207d31..7051034 100644
--- a/src/components/BaseNav/PublicBounced/GasComponents/Echarts.vue
+++ b/src/components/BaseNav/PublicBounced/GasComponents/Echarts.vue
@@ -4,7 +4,7 @@
 
 <script>
 
-// import mapApi from '@/api/mapApi'
+import mapApi from '@/api/mapApi'
 import 'dayjs/locale/es'
 import dayjs from 'dayjs'
 
@@ -12,90 +12,188 @@
   name: 'ECharts',
   data () {
     return {
-      myChart: [],
       days: dayjs(new Date()).format('YYYYMMDDHHmmss'),
-      data: []
+      myChart: [],
+      // x杞存暟鎹�
+      xAxis: [],
+      seriesData: [],
+      seriesName: []
     }
   },
   mounted () {
     this.$nextTick(() => {
-      this.upDateEcharts()
+      this.upDateEchartsData()
     })
   },
   methods: {
+    async upDateEchartsData () {
+      const addDays = dayjs().add(1, 's')
+      const data = {
+        $tagCodeList: 'TJIP45.yyqAI90305,TJIP45.yyqAI90303,TJIP45.yyqFI_90310N,TJIP45.yyqAI90304,TJIP45.yyqAIR001',
+        $startTime: this.dayjs,
+        $endTime: addDays,
+        $step: 15
+      }
+      const result = (await mapApi.DataItems(data)).data
+      for (var i = 0; i < result.length; i++) {
+        // console.log(result[i])
+        this.xAxis.push(result[i].ReadTime)
+        this.seriesData.push(result[i].TagValue)
+        this.seriesName = result[i].UnionTagCode
+        // let num = 0
+        // if (result[i].UnionTagCode === 'TJIP45.lscl2tb552AI10710') {
+        //   num++
+        //   console.log(num)
+        // }
+      }
+      this.upDateEchartsinit()
+    },
     // 鍒濆鍖杄charts
-    upDateEcharts () {
+    upDateEchartsinit () {
       this.myChart = this.$echarts.init(this.$refs.echarts)
-      // this.myChart.setOption(this.options)
-      // setInterval(this.echartsData, 1000)
-      function randomData () {
-        now = new Date(+now + oneDay)
-        value = value + Math.random() * 21 - 10
-        return {
-          name: now.toString(),
-          value: [
-            [now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'),
-            Math.round(value)
-          ]
+      // 鍥捐〃鐨勯厤缃」鏁版嵁
+      const xAxisData = this.xAxis
+      const legendData = [this.seriesName, 'TJIP45.lscl2tb552AISA11201B', 'TJIP45.lscl2tb552AISA11202A', 'TJIP45.lscl2tbAIA-10505-1', 'TJIP45.lscl2tbAIA-10505-2']
+      const seriesData = [
+        {
+          name: this.seriesName,
+          type: 'line',
+          data: this.seriesData,
+          symbolSize: 8,
+          smooth: true,
+          silent: false,
+          barWidth: '50%',
+          animation: true
+        },
+        {
+          name: 'TJIP45.lscl2tb552AISA11201B',
+          type: 'line',
+          stack: '鎬婚噺',
+          smooth: true,
+          symbolSize: 8,
+          data: [2.20, 1.82, 1.91, 2.34, 2.90, 3.30, 3.10]
         }
-      }
-
-      // this.data = []
-      var now = +new Date(1997, 9, 3)
-      var oneDay = 24 * 3600 * 1000
-      var value = Math.random() * 1000
-      for (var i = 0; i < 1000; i++) {
-        this.data.push(randomData())
-      }
+      ]
       const option = {
         title: {
-          text: '鍔ㄦ�佹暟鎹� + 鏃堕棿鍧愭爣杞�'
+          text: '瀹炴椂鏁版嵁',
+          target: 'blank',
+          left: '5%',
+          textStyle: {
+            color: '#fff',
+            fontSize: 15,
+            bottom: 20
+          }
         },
         tooltip: {
-          trigger: 'axis',
-          formatter: function (params) {
-            params = params[0]
-            var date = new Date(params.name)
-            return date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' : ' + params.value[1]
-          },
-          axisPointer: {
-            animation: false
+          trigger: 'axis'
+        },
+        grid: {
+          left: '3%',
+          right: '4%',
+          bottom: '3%',
+          containLabel: true
+        },
+        toolbox: {
+          show: false,
+          feature: {
+            saveAsImage: {}
+          }
+        },
+        dataZoom: [
+          {
+            type: 'inside'
+            // start: 50,
+            // end: 100,
+            // filterMode: 'empty'
+          }
+        ],
+        legend: {
+          data: legendData,
+          textStyle: {
+            color: '#ffffff',
+            fontSize: 12
           }
         },
         xAxis: {
-          type: 'time',
+          type: 'category',
+          boundaryGap: false,
+          axisLabel: {
+            rotate: 20,
+            interval: 0,
+            textStyle: {
+              color: '#fff'
+            }
+          },
           splitLine: {
+            show: true,
+            lineStyle: {
+              type: 'dashed'
+            }
+          },
+          axisTick: {
             show: false
-          }
+          },
+          axisLine: {
+            lineStyle: {
+              color: '#FFFFFF',
+              width: 1
+            }
+          },
+          data: xAxisData
         },
-        yAxis: {
+        yAxis: [{
           type: 'value',
-          boundaryGap: [0, '100%'],
+          name: 'yname',
+          // max: function (value) {
+          //   var max_val_list = []; //鎵�鏈夋樉绀烘姌绾跨殑鏍囧噯鍊�
+          //   if (bzzList && bzzList.length > 0) {
+          //     $.each(bzzList, function (index, item) {
+          //       max_val_list.push(item.bzhui);
+          //     });
+          //   }
+          //   max_val_list = max_val_list.sort(function (a, b) {
+          //     return a - b
+          //   }); //鎺掑簭
+          //   var ma = value.max > max_val_list[max_val_list.length - 1] ? value.max + 5 : max_val_list[max_val_list.length - 1];
+          //   return parseInt(ma);
+          // },
+          axisLabel: {
+            formatter: '{value}',
+            textStyle: {
+              color: '#fff'
+            }
+          },
           splitLine: {
             show: false
+          }, // y杞� 缃戞牸绾夸笉鏄剧ず,
+          axisLine: {
+            lineStyle: {
+              color: '#FFFFFF',
+              width: 1
+            }
           }
-        },
-        series: [{
-          name: '妯℃嫙鏁版嵁',
-          type: 'line',
-          showSymbol: false,
-          hoverAnimation: false,
-          data: this.data
-        }]
+        }, {
+          type: 'value',
+          name: 'dataUnit',
+          axisLabel: {
+            formatter: '{value}',
+            textStyle: {
+              color: '#fff'
+            }
+          },
+          splitLine: {
+            show: false
+          },
+          axisLine: {
+            lineStyle: {
+              color: '#FFFFFF',
+              width: 1
+            }
+          }
+        }],
+        series: seriesData
       }
-
-      setInterval(function () {
-        for (var i = 0; i < 5; i++) {
-          this.data.shift()
-          this.data.push(randomData())
-        }
-
-        // this.myChart.setOption({
-        //   series: [{
-        //     data: this.data
-        //   }]
-        // })
-      }, 1000)
       this.myChart.setOption(option)
     }
   }

--
Gitblit v1.8.0