Selaa lähdekoodia

feat(deviceData): 添加图表配置选项并优化数据加载逻辑

添加opts配置对象以自定义图表显示样式和交互
增加数据长度检查防止空数据初始化图表
allen 2 päivää sitten
vanhempi
commit
6da16957f1
1 muutettua tiedostoa jossa 35 lisäystä ja 2 poistoa
  1. 35 2
      pages/cbd/components/deviceData.vue

+ 35 - 2
pages/cbd/components/deviceData.vue

@@ -86,7 +86,7 @@
       <view class="chart-content">
         <view class="chart-canvas-container" v-if="!show" :key="chartKey">
           <!-- <div id="tempChart" class="chart-canvas"></div> -->
-		      <qiun-data-charts type="line" :chartData="chartData" :canvas2d="true" :inScrollView="true" />
+		      <qiun-data-charts type="line" :chartData="chartData" :canvas2d="true" :inScrollView="true" :opts="opts" :ontouch="true"/>
         </view>
       </view>
     </view>
@@ -306,6 +306,37 @@ export default {
         { name: '湿度', id: 'new_hum' },
         { name: '加热仓温度', id: 'others' },
       ],
+      opts: {
+        type: 'line',
+        xAxis: {
+          disableGrid: true,
+          itemCount: 3,
+          scrollShow: true
+        },
+        yAxis: {
+          disableGrid: true,
+          gridType: 'dash',
+          splitNumber: 5,
+          min: 0,
+          format: (val) => {
+            return Math.round(val)
+          }
+        },
+        extra: {
+          line: {
+            type: 'curve'
+          },
+          tooltip: {
+            format: {
+              name: '',
+              value: (val) => Math.round(val)
+            }
+          }
+        },
+        legend: {
+        },
+        enableScroll: true
+      },
       xData:[],
       yData:[],
       activeChartTab: 0,
@@ -326,7 +357,9 @@ export default {
       handler(newVal, oldVal){
         this.xData = newVal.map(item => this.formatDate(new Date(item.addtime)));
         this.yData = newVal.map(item => Number(item.new_tem) || 0);
-        this.initChart();
+        if(this.xData.length){
+          this.initChart();
+        }
       },
       deep:true,
       immediate:true,