From 14101bd42ce17dfb9d951d0738abe9d303fb3fe5 Mon Sep 17 00:00:00 2001
From: yangfeng <wanwan926_4@163.com>
Date: 星期一, 11 十二月 2023 10:41:39 +0800
Subject: [PATCH] 机器开机率、人员技能比饼图优化

---
 src/views/cockpitPage/components/PerSonnelProductivity.vue |  204 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 142 insertions(+), 62 deletions(-)

diff --git a/src/views/cockpitPage/components/PerSonnelProductivity.vue b/src/views/cockpitPage/components/PerSonnelProductivity.vue
index 5759ea5..407ad78 100644
--- a/src/views/cockpitPage/components/PerSonnelProductivity.vue
+++ b/src/views/cockpitPage/components/PerSonnelProductivity.vue
@@ -16,37 +16,53 @@
 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"],
-        datay: [120, 200, 150, 380, 470, 150, 230],
-      },
+      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";
+      let spirit = "/cockpitPage/order-bg.png";
       if (data) {
         option = {
           color: ["#00FFFF", "#dcb018"],
@@ -55,34 +71,31 @@
             axisPointer: {
               type: "none",
             },
+            textStyle: {
+              color: "#00FFFF",
+            },
+            borderColor: "#00FFFF",
+            backgroundColor: "#238d8d6b",
+            valueFormatter: function (value) {
+              return value + "%";
+            },
           },
           grid: {
             right: "80px",
             bottom: "60px",
-            left: "60px",
+            left: "70px",
             top: "30px",
           },
           dataZoom: [
             {
               type: "inside",
-              // show: true, //鏄剧ず婊氬姩鏉�
-              start: 0,
-              end: 100,
               yAxisIndex: 0,
-              minSpan: 20,
-              maxSpan: 100,
-              // handleSize: 8
-            },
-            {
-              //   type: 'slider', //涓や釜涓�涓槸slider锛屼竴涓槸inside锛宻lider鏄鍔犳粴鍔ㄦ潯浠ュ強榧犳爣鎷栧姩婊氬姩鏉″姛鑳斤紝inside鍒欐槸榧犳爣婊氳疆婊氬姩婊氬姩鏉°��
-              type: "inside",
-              // show: true,
-              // realtime : true,
-              yAxisIndex: 0,
-              minSpan: 20,
-              maxSpan: 100,
-              start: 0,
-              end: 100,
+              show: false,
+              startValue: this.startValue, // 浠庡ご寮�濮�
+              endValue: this.endValue, // 涓�娆℃�у睍绀哄嚑涓�
+              zoomOnMouseWheel: false,
+              moveOnMouseWheel: true,
+              moveOnMouseMove: true,
             },
           ],
           legend: {
@@ -108,9 +121,10 @@
                 // rotate:45,
                 margin: 10,
                 show: true,
+                fontSize: 12,
                 textStyle: {
                   color: function (params, index) {
-                    let colorList = ["#dcb018", "#00FFFF"];
+                    let colorList = ["#fec718", "#00FFFF"];
                     if (index % 2 == 0) {
                       return colorList[0];
                     } else {
@@ -118,14 +132,20 @@
                     }
                   },
                 },
+                formatter: function (value) {
+                  if (value.length > 5) {
+                    return `${value.slice(0, 4)}...`;
+                  }
+                  return value;
+                },
               },
               data: data.datax ? data.datax : [],
             },
           ],
           xAxis: [
             {
-              type: "",
-              name: "鍗曚綅锛氫欢",
+              type: "value",
+              // name: "鍗曚綅锛氫欢",
               // min: data.yAxis[0].min?data.yAxis.min:0,
               minInterval: 1, //鍧愭爣杞存槸鏁存暟
               max: Math.ceil(eval(`Math.max(${data.datay})`) / 5) * 5, //鏁版嵁鏈�澶у�煎姞3
@@ -151,30 +171,51 @@
               axisTick: {
                 show: false,
               },
-
               axisLabel: {
                 textStyle: {
                   color: "#00FFFF",
+                },
+                formatter: function (value) {
+                  return `${value}%`;
                 },
               },
             },
           ],
           series: [
             {
-              type: "bar",
+              type: "pictorialBar",
               name: "",
-              barWidth: "15",
+              symbol: spirit,
+              symbolRepeat: true,
+              symbolMargin: "25%",
+              symbolClip: true,
+              symbolSize: [4, 11],
+              barCategoryGap: "40%",
               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: "#fccd1d",
+                  },
+                },
               },
               itemStyle: {
                 normal: {
                   //鏌卞舰鍥惧渾瑙掞紝鍒濆鍖栨晥鏋�
                   barBorderRadius: [4, 4, 0, 0],
                   color: function (params) {
-                    let colorList = ["#dcb018", "#00FFFF"];
+                    let colorList = ["#fccd1d", "#00FFFF"];
                     if (params.dataIndex % 2 == 0) {
                       return colorList[0];
                     } else {
@@ -187,8 +228,21 @@
             },
           ],
         };
+        this.chartTimer = setInterval(function () {
+          if (option.dataZoom[0].endValue == data.datay.length) {
+            option.dataZoom[0].startValue = 0;
+            option.dataZoom[0].endValue = 5;
+          } else {
+            option.dataZoom[0].endValue = option.dataZoom[0].endValue + 1;
+            option.dataZoom[0].startValue = option.dataZoom[0].startValue + 1;
+          }
+          myChart.setOption(option);
+        }, 4000);
 
         option && myChart.setOption(option);
+        window.addEventListener("resize", function () {
+          myChart.resize();
+        });
       } else {
         option = {};
         myChart.setOption(option, true);
@@ -196,24 +250,41 @@
     },
     getChartRight(chartName, data) {
       let chartDom = this.$refs[chartName];
-      let myChart = echarts.init(chartDom);
+      if (
+        myRightChart != null &&
+        myRightChart != "" &&
+        myRightChart != undefined
+      ) {
+        myRightChart.dispose(); //閿�姣�
+      }
+      myRightChart = echarts.init(chartDom);
       let img = "/cockpitPage/dotted-circle.png";
+      let height = myRightChart.getHeight() / 1;
+      let width = height + 5;
       let option;
       if (data) {
         option = {
           color: ["#dcb018", "#735b09", "#ebd68e", "#c7b36e"],
           tooltip: {
             trigger: "item",
+            textStyle: {
+              color: "#00FFFF",
+            },
+            borderColor: "#00FFFF",
+            backgroundColor: "#238d8d6b",
+            valueFormatter: function (value) {
+              return value + "%";
+            },
           },
           graphic: {
             elements: [
               {
                 type: "image",
-                z: 3,
+                // z: 3,
                 style: {
                   image: img,
-                  width: 118,
-                  height: 118,
+                  width: width,
+                  height: height,
                 },
                 left: "center",
                 top: "center",
@@ -223,25 +294,34 @@
           },
           series: [
             {
-              name: "Access From",
+              name: "浜哄憳鎶�鑳芥瘮",
               type: "pie",
-              // center: ['80%', '46%'],
-              radius: ["52%", "65%"],
-              // minAngle: 20,
-              // startAngle: 60,
+              radius: ["52%", "62%"],
               avoidLabelOverlap: false,
-
               label: {
                 normal: {
                   position: "outer",
-                  padding: [0, -55],
+                  padding: [0, -62],
                   color: "#01f7fd",
                   fontSize: 12,
-                  borderWidth: 20,
+                  borderWidth: 5,
                   borderRadius: 4,
                   formatter: function (params) {
-                    let str = params.name + params.value + "%";
-                    return str;
+                    let label =
+                      params.name.length > 4
+                        ? `${params.name.slice(0, 3)}...`
+                        : params.name;
+                    return `{a|${label}} {b|${params.value + "%"}}`;
+                  },
+                  rich: {
+                    a: {
+                      color: "#00ffff",
+                      fontSize: 14,
+                    },
+                    b: {
+                      color: "#fccd1d",
+                      fontSize: 14,
+                    },
                   },
                 },
               },
@@ -255,7 +335,7 @@
               },
               labelLine: {
                 show: true,
-                length: 5,
+                length: 4,
                 length2: 70,
                 lineStyle: {
                   color: "#dcb018",
@@ -270,10 +350,10 @@
           ],
         };
 
-        option && myChart.setOption(option);
+        option && myRightChart.setOption(option);
       } else {
         option = {};
-        myChart.setOption(option, true);
+        myRightChart.setOption(option, true);
       }
     },
   },
@@ -283,7 +363,7 @@
 <style scoped lang="scss">
 .bar-chart {
   width: 100%;
-  height: calc(100% - 20px);
+  height: calc(100% - 10px);
   padding: 20px 0 0;
 
   .bar-contents {
@@ -292,7 +372,7 @@
 
     .chart-left {
       width: calc(60% - 20px);
-      height: 100%;
+      height: calc(100% - 20px);
       margin-right: 20px;
       float: left;
       border: 1px solid #00ffff;
@@ -302,7 +382,7 @@
     .chart-right {
       width: 40%;
       float: left;
-      height: 100%;
+      height: calc(100% - 20px);
       position: relative;
       .chart-bg {
         width: 100%;

--
Gitblit v1.8.0