From 93d04e35d6ff02470687b73ff7494b62bdc85f2c Mon Sep 17 00:00:00 2001
From: yangfeng <wanwan926_4@163.com>
Date: 星期三, 06 十二月 2023 16:32:38 +0800
Subject: [PATCH] 页面背景图及饼图显示优化

---
 src/views/cockpitPage/components/PerSonnelProductivity.vue |  129 +++++++++++++++++++++++++++---------------
 1 files changed, 83 insertions(+), 46 deletions(-)

diff --git a/src/views/cockpitPage/components/PerSonnelProductivity.vue b/src/views/cockpitPage/components/PerSonnelProductivity.vue
index 5814dcf..f9ef786 100644
--- a/src/views/cockpitPage/components/PerSonnelProductivity.vue
+++ b/src/views/cockpitPage/components/PerSonnelProductivity.vue
@@ -16,46 +16,50 @@
 import ChartTitle from "@/views/cockpitPage/components/ChartTitle.vue";
 //寮曞叆echart
 import * as echarts from "echarts";
+let myChart;
+let myRightChart;
 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",
-        ],
-        datay: [120, 200, 150, 380, 470, 150, 230, 330, 190, 440],
-      },
+      startValue: 0,
+      endValue: 5,
+      chartTimer: null,
     };
   },
-  mounted() {
-    this.pieChart("chart", this.chartData);
-    let chartData2 = [
-      { value: 10, name: "涓�绫�" },
-      { value: 20, name: "浜岀被" },
-      { value: 60, name: "涓夌被" },
-      { value: 10, name: "鍥涚被" },
-    ];
-    this.getChartRight("chart2", chartData2);
+  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);
+      // let myChart = echarts.init(chartDom);
+      if (myChart != null && myChart != "" && myChart != undefined) {
+        myChart.dispose(); //閿�姣�
+      }
+      myChart = echarts.init(chartDom);
       let option;
       let lineColor = "#35ddc74d";
       if (data) {
@@ -70,7 +74,7 @@
           grid: {
             right: "80px",
             bottom: "60px",
-            left: "60px",
+            left: "70px",
             top: "30px",
           },
           dataZoom: [
@@ -78,8 +82,11 @@
               type: "inside",
               yAxisIndex: 0,
               show: false,
-              startValue: 0, // 浠庡ご寮�濮�
-              endValue: 5, // 涓�娆℃�у睍绀哄嚑涓�
+              startValue: this.startValue, // 浠庡ご寮�濮�
+              endValue: this.endValue, // 涓�娆℃�у睍绀哄嚑涓�
+              zoomOnMouseWheel: false,
+              moveOnMouseWheel: true,
+              moveOnMouseMove: true,
             },
           ],
           legend: {
@@ -105,6 +112,7 @@
                 // rotate:45,
                 margin: 10,
                 show: true,
+                fontSize: 12,
                 textStyle: {
                   color: function (params, index) {
                     let colorList = ["#dcb018", "#00FFFF"];
@@ -114,6 +122,12 @@
                       return colorList[1];
                     }
                   },
+                },
+                formatter: function (value) {
+                  if (value.length > 5) {
+                    return `${value.slice(0, 4)}...`;
+                  }
+                  return value;
                 },
               },
               data: data.datax ? data.datax : [],
@@ -148,10 +162,12 @@
               axisTick: {
                 show: false,
               },
-
               axisLabel: {
                 textStyle: {
                   color: "#00FFFF",
+                },
+                formatter: function (value) {
+                  return `${value}%`;
                 },
               },
             },
@@ -164,7 +180,21 @@
               label: {
                 show: true,
                 position: "right",
-                color: "#00FFFF",
+                formatter: function (params) {
+                  if (params.dataIndex % 2 == 0) {
+                    return `{a|${params.value}%}`;
+                  } else {
+                    return `{b|${params.value}%}`;
+                  }
+                },
+                rich: {
+                  a: {
+                    color: "#00FFFF",
+                  },
+                  b: {
+                    color: "#dcb018",
+                  },
+                },
               },
               itemStyle: {
                 normal: {
@@ -184,10 +214,8 @@
             },
           ],
         };
-
-        setInterval(function () {
-          // 姣忔鍚戝乏婊戝姩涓�涓紝鏈�鍚庝竴涓粠澶村紑濮嬨��
-          if (option.dataZoom[0].endValue == that.chartData.datay.length) {
+        this.chartTimer = setInterval(function () {
+          if (option.dataZoom[0].endValue == data.datay.length) {
             option.dataZoom[0].startValue = 0;
             option.dataZoom[0].endValue = 5;
           } else {
@@ -208,7 +236,15 @@
     },
     getChartRight(chartName, data) {
       let chartDom = this.$refs[chartName];
-      let myChart = echarts.init(chartDom);
+      // let myRightChart = echarts.init(chartDom);
+      if (
+        myRightChart != null &&
+        myRightChart != "" &&
+        myRightChart != undefined
+      ) {
+        myRightChart.dispose(); //閿�姣�
+      }
+      myRightChart = echarts.init(chartDom);
       let img = "/cockpitPage/dotted-circle.png";
       let option;
       if (data) {
@@ -224,8 +260,8 @@
                 z: 3,
                 style: {
                   image: img,
-                  width: 238,
-                  height: 238,
+                  width: 240,
+                  height: 240,
                 },
                 left: "center",
                 top: "center",
@@ -237,10 +273,7 @@
             {
               name: "Access From",
               type: "pie",
-              // center: ['80%', '46%'],
               radius: ["52%", "62%"],
-              // minAngle: 20,
-              // startAngle: 60,
               avoidLabelOverlap: false,
 
               label: {
@@ -252,7 +285,11 @@
                   borderWidth: 5,
                   borderRadius: 4,
                   formatter: function (params) {
-                    return `{a|${params.name}} {b|${params.value + "%"}}`;
+                    let label =
+                      params.name.length > 5
+                        ? `${params.name.slice(0, 4)}...`
+                        : params.name;
+                    return `{a|${label}} {b|${params.value + "%"}}`;
                   },
                   rich: {
                     a: {
@@ -277,7 +314,7 @@
               labelLine: {
                 show: true,
                 length: 4,
-                length2: 80,
+                length2: 70,
                 lineStyle: {
                   color: "#dcb018",
                 },
@@ -291,10 +328,10 @@
           ],
         };
 
-        option && myChart.setOption(option);
+        option && myRightChart.setOption(option);
       } else {
         option = {};
-        myChart.setOption(option, true);
+        myRightChart.setOption(option, true);
       }
     },
   },
@@ -304,7 +341,7 @@
 <style scoped lang="scss">
 .bar-chart {
   width: 100%;
-  height: calc(100% - 20px);
+  height: calc(100% - 10px);
   padding: 20px 0 0;
 
   .bar-contents {

--
Gitblit v1.8.0