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/DeviceChart.vue |  245 ++++++++++++++++++++++++++++++------------------
 1 files changed, 152 insertions(+), 93 deletions(-)

diff --git a/src/views/cockpitPage/components/DeviceChart.vue b/src/views/cockpitPage/components/DeviceChart.vue
index be8a045..a39f3d6 100644
--- a/src/views/cockpitPage/components/DeviceChart.vue
+++ b/src/views/cockpitPage/components/DeviceChart.vue
@@ -14,119 +14,144 @@
 
 <script>
 //寮曞叆echart
-import * as echarts from 'echarts'
+import * as echarts from "echarts";
+let myChart;
 export default {
-  components: {
+  components: {},
+  props: {
+    chartData: {
+      type: Object,
+      require: true,
+      default: () => {
+        return {
+          datax: [],
+          datay: [],
+        };
+      },
+    },
   },
-  props: {},
   data() {
     return {
-      chartData: {
-        datax: ['璁惧1', '璁惧2', '璁惧3', '璁惧4', '璁惧5', '璁惧6'],
-        datay: [10, 20, 15, 38, 47, 50, 20],
-      }
+      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 chartDom = this.$refs[chartName]
-      let myChart = echarts.init(chartDom);
+      let that = this;
+      clearInterval(this.chartTimer);
+      let chartDom = this.$refs[chartName];
+      if (myChart != null && myChart != "" && myChart != undefined) {
+        myChart.dispose(); //閿�姣�
+      }
+      myChart = echarts.init(chartDom);
       let option;
-      let lineColor = '#35ddc74d'
+      let lineColor = "#35ddc74d";
+      let spirit = "/cockpitPage/order-bg.png";
       if (data) {
         option = {
-          color: ['#00FFFF', '#dcb018'],
+          color: ["#00FFFF", "#fccd1d"],
           tooltip: {
-            trigger: 'axis',
+            trigger: "axis",
             axisPointer: {
-              type: 'none'
+              type: "none",
+            },
+            textStyle: {
+              color: "#00FFFF",
+            },
+            borderColor: "#00FFFF",
+            backgroundColor: "#238d8d6b",
+            valueFormatter: function (value) {
+              return value + "%";
             },
           },
           grid: {
             right: "80px",
-            bottom: '60px',
-            left: '60px',
-            top: '30px',
+            bottom: "60px",
+            left: "70px",
+            top: "30px",
           },
           dataZoom: [
             {
-              type: 'inside',
-              // show: true, //鏄剧ず婊氬姩鏉�
-              start: 0,
-              end: 100,
+              type: "inside",
               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: that.startValue, // 浠庡ご寮�濮�
+              endValue: that.endValue, // 涓�娆℃�у睍绀哄嚑涓�
+              zoomOnMouseWheel: false,
+              moveOnMouseWheel: true,
+              moveOnMouseMove: true,
             },
           ],
           legend: {
             itemWidth: 8,
             itemHeight: 8,
-            itemGap: 35,//闂磋窛
-            bottom: '5px',
-            left: 'center',
+            itemGap: 35, //闂磋窛
+            bottom: "5px",
+            left: "center",
           },
           yAxis: [
             {
-              type: 'category',
+              type: "category",
               axisTick: {
-                show: false
+                show: false,
               },
               axisLine: {
                 show: true,
                 lineStyle: {
                   color: lineColor,
-                }
+                },
               },
               axisLabel: {
                 // rotate:45,
                 margin: 10,
                 show: true,
+                fontSize: 12,
                 textStyle: {
                   color: function (params, index) {
-                    let colorList = ['#dcb018', '#00FFFF']
+                    let colorList = ["#fccd1d", "#00FFFF"];
                     if (index % 2 == 0) {
-                      return colorList[0]
+                      return colorList[0];
                     } else {
-                      return colorList[1]
+                      return colorList[1];
                     }
+                  },
+                },
+                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
-              interval: Math.ceil(eval(`Math.max(${data.datay})`) / 6) * 6 / 6,
-              position: 'left',
+              minInterval: 1, //鍧愭爣杞存槸鏁存暟
+              max: Math.ceil(eval(`Math.max(${data.datay})`) / 5) * 5, //鏁版嵁鏈�澶у�煎姞3
+              interval:
+                (Math.ceil(eval(`Math.max(${data.datay})`) / 6) * 6) / 6,
+              position: "left",
               axisLine: {
                 show: true,
                 lineStyle: {
-                  color: '#0a112B',
-                }
+                  color: "#0a112B",
+                },
               },
               nameTextStyle: {
                 color: "#00FFFF",
@@ -136,50 +161,84 @@
                 lineStyle: {
                   // 浣跨敤娣辨祬鐨勯棿闅旇壊
                   color: lineColor,
-                }
+                },
               },
               axisTick: {
-                show: false
+                show: false,
               },
-
               axisLabel: {
                 textStyle: {
-                  color: '#00FFFF'
+                  color: "#00FFFF",
                 },
-                formatter: '{value}%'
-              }
+                formatter: function (value) {
+                  return `${value}%`;
+                },
+              },
             },
           ],
           series: [
             {
-              type: 'bar',
-              name: '',
-              barWidth: '15',
-              label:{
-                show:true,
-                position:'right',
-                color: '#00FFFF'
+              type: "pictorialBar",
+              name: "",
+              symbol: spirit,
+              symbolRepeat: true,
+              symbolMargin: "25%",
+              symbolClip: true,
+              symbolSize: [4, 11],
+              barCategoryGap: "40%",
+              label: {
+                show: true,
+                position: "right",
+                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]
+                      return colorList[0];
                     } else {
-                      return colorList[1]
+                      return colorList[1];
                     }
-                  }
+                  },
                 },
               },
               data: data.datay,
             },
-          ]
+          ],
         };
 
+        this.chartTimer = setInterval(function () {
+          if (option.dataZoom[0].endValue == data.datay.length) {
+            option.dataZoom[0].startValue = that.startValue;
+            option.dataZoom[0].endValue = that.endValue;
+          } 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);
@@ -194,30 +253,30 @@
   width: 100%;
   height: calc(100% - 0px);
   padding: 0px 0 0;
-  border: 1px solid #00FFFF;
+  border: 1px solid #00ffff;
   box-sizing: border-box;
   position: relative;
   .top-view {
-      height:38px;
-      margin-top: -1px;
-      margin-left: -1px;
-      position: relative;
-      left:0;
-      top:0;
-      .top-title {
-        width: calc(100% - 10px);
-        margin: auto;
-        height:38px;
-        line-height:38px;
-        position:absolute;
-        top:0;
-        left:10px;
-        color: #01f7fd;
-        font-size: 14px;
-        font-family: "Arial Negreta", "Arial Normal", "Arial";
-        font-weight: 700;
-      }
+    height: 38px;
+    margin-top: -1px;
+    margin-left: -1px;
+    position: relative;
+    left: 0;
+    top: 0;
+    .top-title {
+      width: calc(100% - 10px);
+      margin: auto;
+      height: 38px;
+      line-height: 38px;
+      position: absolute;
+      top: 0;
+      left: 10px;
+      color: #01f7fd;
+      font-size: 14px;
+      font-family: "Arial Negreta", "Arial Normal", "Arial";
+      font-weight: 700;
     }
+  }
   .bar-contents {
     width: 100%;
     height: calc(100% - 40px);

--
Gitblit v1.8.0