From 1dbdda3517a01851d8d9894b22e61aa4462b541c Mon Sep 17 00:00:00 2001
From: yangfeng <wanwan926_4@163.com>
Date: 星期四, 07 十二月 2023 19:16:36 +0800
Subject: [PATCH] tooltip值优化

---
 src/views/cockpitPage/components/MaterialChart.vue |   73 ++++++++++++++++++++++++------------
 1 files changed, 48 insertions(+), 25 deletions(-)

diff --git a/src/views/cockpitPage/components/MaterialChart.vue b/src/views/cockpitPage/components/MaterialChart.vue
index ec8e420..1e95123 100644
--- a/src/views/cockpitPage/components/MaterialChart.vue
+++ b/src/views/cockpitPage/components/MaterialChart.vue
@@ -11,40 +11,48 @@
 import ChartTitle from "@/views/cockpitPage/components/ChartTitle.vue";
 //寮曞叆echart
 import * as echarts from "echarts";
+let myChart;
 export default {
   components: {
     ChartTitle,
   },
-  props: {},
+  props: {
+    chartData: {
+      type: Object,
+      require: true,
+      default: () => {
+        return {
+          datax: [],
+          datay: [],
+        };
+      },
+    },
+  },
   data() {
     return {
-      chartData: {
-        datax: [
-          "浜у搧1",
-          "浜у搧2",
-          "浜у搧3",
-          "浜у搧4",
-          "浜у搧5",
-          "浜у搧6",
-          "浜у搧7",
-          "浜у搧8",
-          "浜у搧9",
-          "浜у搧10",
-        ],
-        datay: [120, 200, 150, 380, 470, 150, 230, 130, 210, 145, 330],
-      },
+      startValue: 0,
+      endValue: 5,
+      chartTimer: null,
     };
   },
-  mounted() {
-    this.pieChart("chart", this.chartData);
+  watch: {
+    "chartData.datay"(val) {
+      this.startValue = 0;
+      this.endValue = 5;
+      this.pieChart("chart", this.chartData);
+    },
   },
-  watch: {},
+  mounted() {},
   methods: {
     //鍦ㄨ亴
     pieChart(chartName, data) {
       let that = this;
+      clearInterval(this.chartTimer);
       let chartDom = this.$refs[chartName];
-      let myChart = echarts.init(chartDom);
+      if (myChart != null && myChart != "" && myChart != undefined) {
+        myChart.dispose(); //閿�姣�
+      }
+      myChart = echarts.init(chartDom);
       let option;
       let lineColor = "#35ddc74d";
       if (data) {
@@ -55,11 +63,14 @@
             axisPointer: {
               type: "none",
             },
+            valueFormatter: function (value) {
+              return "鐗╂枡涓嶈冻鐨勬暟閲�:" + value;
+            },
           },
           grid: {
             right: "80px",
             bottom: "60px",
-            left: "60px",
+            left: "70px",
             top: "30px",
           },
           dataZoom: [
@@ -67,8 +78,11 @@
               type: "inside",
               yAxisIndex: 0,
               show: false,
-              startValue: 0, // 浠庡ご寮�濮�
-              endValue: 5, // 涓�娆℃�у睍绀哄嚑涓�
+              startValue: that.startValue, // 浠庡ご寮�濮�
+              endValue: that.endValue, // 涓�娆℃�у睍绀哄嚑涓�
+              zoomOnMouseWheel: false,
+              moveOnMouseWheel: true,
+              moveOnMouseMove: true,
             },
           ],
           legend: {
@@ -94,6 +108,7 @@
                 // rotate:45,
                 margin: 10,
                 show: true,
+                fontSize: 12,
                 textStyle: {
                   color: function (params, index) {
                     let colorList = ["#dcb018", "#00FFFF"];
@@ -103,6 +118,12 @@
                       return colorList[1];
                     }
                   },
+                },
+                formatter: function (value) {
+                  if (value.length > 5) {
+                    return `${value.slice(0, 4)}...`;
+                  }
+                  return value;
                 },
               },
               data: data.datax ? data.datax : [],
@@ -142,6 +163,9 @@
                 textStyle: {
                   color: "#00FFFF",
                 },
+                formatter: function (value) {
+                  return `${(value / 1000).toFixed(1)}k`;
+                },
               },
             },
           ],
@@ -168,8 +192,7 @@
             },
           ],
         };
-        setInterval(function () {
-          // 姣忔鍚戝乏婊戝姩涓�涓紝鏈�鍚庝竴涓粠澶村紑濮嬨��
+        this.chartTimer = setInterval(function () {
           if (option.dataZoom[0].endValue == that.chartData.datay.length) {
             option.dataZoom[0].startValue = 0;
             option.dataZoom[0].endValue = 5;

--
Gitblit v1.8.0