From da4d9e70d2c37f59a365b0fb88ad70e8c1ba79b4 Mon Sep 17 00:00:00 2001
From: yangfeng <wanwan926_4@163.com>
Date: 星期一, 11 十二月 2023 10:25:01 +0800
Subject: [PATCH] 机器开机率优化

---
 src/views/cockpitPage/components/BarChart.vue |  569 ++++++++++++++++++++++++++++++--------------------------
 1 files changed, 308 insertions(+), 261 deletions(-)

diff --git a/src/views/cockpitPage/components/BarChart.vue b/src/views/cockpitPage/components/BarChart.vue
index 1d090ae..0cf8a5c 100644
--- a/src/views/cockpitPage/components/BarChart.vue
+++ b/src/views/cockpitPage/components/BarChart.vue
@@ -3,12 +3,8 @@
     <ChartTitle name="杞﹂棿姝e搧鐜�"></ChartTitle>
     <div class="bar-contents">
       <div class="bar-total">
-        <div class="bar-item">
-          褰撴棩鍚堣鐢熶骇锛歿{ chartData.total }}
-        </div>
-        <div class="bar-item">
-          姝e搧鐜囷細{{ chartData.rate }}
-        </div>
+        <div class="bar-item">7鏃ュ悎璁$敓浜э細{{ chartData.total }}</div>
+        <div class="bar-item">姝e搧鐜囷細{{ chartData.rate }}%</div>
       </div>
       <div class="chart" ref="chart"></div>
     </div>
@@ -18,282 +14,333 @@
 <script>
 import ChartTitle from "@/views/cockpitPage/components/ChartTitle.vue";
 //寮曞叆echart
-import * as echarts from 'echarts'
+import * as echarts from "echarts";
+let myChart;
 export default {
   components: {
     ChartTitle,
   },
-  props: {},
+  props: {
+    chartData: {
+      type: Object,
+      require: true,
+      default: () => {
+        return {
+          total: 0,
+          rate: "0",
+          datax: [],
+          datay: [],
+          datay2: [],
+        };
+      },
+    },
+  },
   data() {
     return {
-      chartData:{
-        total:1000,
-        rate:'99%',
-        datax:['绗竴杞﹂棿', '绗簩杞﹂棿', '绗笁杞﹂棿', '绗洓杞﹂棿','绗簲杞﹂棿','绗叚杞﹂棿',],
-        datay:[120, 200, 150, 180, 170, 150, 130,180, 140],
-        datay2:[20, 30, 50, 40, 70, 50, 30,80,40],
-      }
+      // chartData: {
+      //   total: 1000,
+      //   rate: "99%",
+      //   datax: [
+      //     "绗竴杞﹂棿",
+      //     "绗簩杞﹂棿",
+      //     "绗笁杞﹂棿",
+      //     "绗洓杞﹂棿",
+      //     "绗簲杞﹂棿",
+      //     "绗叚杞﹂棿",
+      //     "绗竷杞﹂棿",
+      //     "绗叓杞﹂棿",
+      //     "绗節杞﹂棿",
+      //   ],
+      //   datay: [120, 200, 150, 180, 170, 150, 130, 180, 140],
+      //   datay2: [20, 30, 50, 40, 70, 50, 30, 80, 40],
+      // },
+      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() {
+    // this.pieChart("chart", this.chartData);
+  },
   methods: {
     //鍦ㄨ亴
-    pieChart(chartName,data){
-          let chartDom = this.$refs[chartName]
-          let myChart = echarts.init(chartDom);
-          let option;
-          let lineColor='#35ddc74d'
-          if(data){
-            option = {
-              color:['#dcb018','#00FFFF'],
-              tooltip: {
-                trigger: 'axis',
-                axisPointer: {
-                  type: 'none'
-                },
-                textStyle:{
-                  color:'#00FFFF',
-                },
-                borderColor:'#00FFFF',
-                backgroundColor:'rbga(1,247,253,0.6)',
-                formatter:function(a){
-                  let list=[]
-                  let listItem=''
-                  let firstString='<span style=width:70px;display:inline-block">'+
-                      '鐢熶骇鎬绘暟'+
-                      '</span>&nbsp;'+
-                      data.total
-                      list.push(firstString)
-                  for(let i in a){
-                    let str='<span style=width:70px;display:inline-block">'+
-                      a[i].seriesName+
-                      '</span>&nbsp;'+
-                      a[i].value
-                      
-                    list.push(str)
-                  }
-                  let lastString='<span style=width:70px;display:inline-block">'+
-                      '姝e搧鐜�'+
-                      '</span>&nbsp;'+
-                      data.rate
-                      list.push(lastString)
-                  listItem=list.join('<br>')
-                  return '<div class="showBox">'+listItem+'</div>'
-                }
-              },
-              grid: {
-                right: "10px",
-                bottom:'60px',
-                left:'10px',
-                top:'10px',
-              },
-              dataZoom: [
-                {
-                  type: 'inside',
-                  // show: true, //鏄剧ず婊氬姩鏉�
-                  start:0,
-                  end: 100,
-                  xAxisIndex: 0,
-                  minSpan:20,
-                  maxSpan:100,
-                  // handleSize: 8
-                },
-                {
-                  //   type: 'slider', //涓や釜涓�涓槸slider锛屼竴涓槸inside锛宻lider鏄鍔犳粴鍔ㄦ潯浠ュ強榧犳爣鎷栧姩婊氬姩鏉″姛鑳斤紝inside鍒欐槸榧犳爣婊氳疆婊氬姩婊氬姩鏉°��
-                  type: 'inside',
-                  // show: true,
-                  // realtime : true,
-                  xAxisIndex: 0,
-                  minSpan:20,
-                  maxSpan:100,
-                  start: 0,
-                  end: 100
-                },
-              ],
-              legend: {
-                itemWidth: 8,
-                itemHeight: 8,
-                itemGap: 35,//闂磋窛
-                bottom:'5px',
-                left:'center',
-                data:[
-                  {
-                    name:'姝e搧鏁伴噺',
-                    icon:'circle',
-                    textStyle:{
-                      color:'#dcb018'
-                    }
-                  },
-                  {
-                    name:'娆″搧鏁伴噺',
-                    icon:'circle',
-                    textStyle:{
-                      color:'#00FFFF'
-                    }
-                  },
-                ],
-              },
-              xAxis: [
-                {
-                  type: 'category',
-                  axisTick: {
-                    show: false
-                  },
-                  axisLine: {
-                    show: true,
-                    lineStyle: {
-                      color:lineColor,
-                    }
-                  },
-                  axisLabel:{
-                    // rotate:45,
-                    margin: 10,
-                    show: true,
-                    textStyle: {
-                      color: '#00FFFF'
-                    },
-                  },
-                  data: data.datax?data.datax:[],
-                }
-              ],
-              yAxis: [
-                {
-                  type: '',
-                  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})`)/5)*5 / 5,
-                  position: 'left',
-                  axisLine: {
-                    show: true,
-                    lineStyle: {
-                      color:lineColor,
-                    }
-                  },
-                  nameTextStyle:{
-                    color:"#00FFFF",
-                  },
-                  splitLine: {
-                    show: true,
-                    lineStyle: {
-                      // 浣跨敤娣辨祬鐨勯棿闅旇壊
-                      color: lineColor,
-                    }
-                  },
-                  axisTick: {
-                    show: false
-                  },
-                  axisLabel: {
-                    textStyle: {
-                      color: '#9B9B9B'
-                    },
-                    formatter: ''
-                  }
-                },
-                {
-                  type: '',
-                  name: '',
-                  // min: data.yAxis[0].min?data.yAxis.min:0,
-                  minInterval: 1,//鍧愭爣杞存槸鏁存暟
-                  max:Math.ceil(eval(`Math.max(${data.datay2})`)/5)*5,//鏁版嵁鏈�澶у�煎姞3
-                  interval: Math.ceil(eval( `Math.max(${data.datay2})`)/5)*5 / 5,
-                  position: 'right',
-                  axisLine: {
-                    show: true,
-                    lineStyle: {
-                      color:lineColor,
-                    }
-                  },
-                  nameTextStyle:{
-                    color:"#00FFFF",
-                  },
-                  splitLine: {
-                    show: true,
-                    lineStyle: {
-                      // 浣跨敤娣辨祬鐨勯棿闅旇壊
-                      color:lineColor,
-                    }
-                  },
-                  axisTick: {
-                    show: false
-                  },
-                  axisLabel: {
-                    textStyle: {
-                      color: '#9B9B9B'
-                    },
-                    formatter: ''
-                  }
-                }
-              ],
-              series:[
-                {
-                  type: 'bar',
-                  name: '姝e搧鏁伴噺',
-                  barWidth: '20%',
-                  itemStyle: {
-                    normal: {
-                      //鏌卞舰鍥惧渾瑙掞紝鍒濆鍖栨晥鏋�
-                      barBorderRadius:[4, 4, 0, 0],
-                    }
-                  },
-                  data: data.datay,
-                },
-                {
-                  type: 'bar',
-                  name: '娆″搧鏁伴噺',
-                  barWidth: '20%',
-                  itemStyle: {
-                    normal: {
-                      //鏌卞舰鍥惧渾瑙掞紝鍒濆鍖栨晥鏋�
-                      barBorderRadius:[4, 4, 0, 0],
-                    }
-                  },
-                  data: data.datay2,
-                }
-              ]
-            };
+    pieChart(chartName, data) {
+      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 spirit = "/cockpitPage/order-bg.png";
+      if (data) {
+        option = {
+          color: ["#fccd1d", "#00FFFF"],
+          tooltip: {
+            trigger: "axis",
+            axisPointer: {
+              type: "none",
+            },
+            textStyle: {
+              color: "#00FFFF",
+            },
+            borderColor: "#00FFFF",
+            backgroundColor: "#238d8d6b",
+            formatter: function (a) {
+              let list = [];
+              let listItem = "";
+              let firstString =
+                '<span style=width:70px;display:inline-block">' +
+                "鐢熶骇鎬绘暟" +
+                "</span>&nbsp;" +
+                data.total;
+              list.push(firstString);
+              for (let i in a) {
+                let str =
+                  '<span style=width:70px;display:inline-block">' +
+                  a[i].seriesName +
+                  "</span>&nbsp;" +
+                  a[i].value;
 
-            option && myChart.setOption(option);
-          }else{
-            option={};
-            myChart.setOption(option,true);
+                list.push(str);
+              }
+              let lastString =
+                '<span style=width:70px;display:inline-block">' +
+                "姝e搧鐜�" +
+                "</span>&nbsp;" +
+                data.rate +
+                "%";
+              list.push(lastString);
+              listItem = list.join("<br>");
+              return '<div class="showBox">' + listItem + "</div>";
+            },
+          },
+          grid: {
+            right: "10px",
+            bottom: "60px",
+            left: "10px",
+            top: "10px",
+          },
+          dataZoom: [
+            {
+              type: "inside",
+              xAxisIndex: 0,
+              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",
+            data: [
+              {
+                name: "姝e搧鏁伴噺",
+                icon: "circle",
+                textStyle: {
+                  color: "#fccd1d",
+                },
+              },
+              {
+                name: "娆″搧鏁伴噺",
+                icon: "circle",
+                textStyle: {
+                  color: "#00FFFF",
+                },
+              },
+            ],
+          },
+          xAxis: [
+            {
+              type: "category",
+              axisTick: {
+                show: false,
+              },
+              axisLine: {
+                show: true,
+                lineStyle: {
+                  color: lineColor,
+                },
+              },
+              axisLabel: {
+                margin: 10,
+                show: true,
+                textStyle: {
+                  color: "#00FFFF",
+                },
+                formatter: function (value) {
+                  if (value.length > 4) {
+                    return `${value.slice(0, 3)}...`;
+                  }
+                  return value;
+                },
+              },
+              data: data.datax ? data.datax : [],
+            },
+          ],
+          yAxis: [
+            {
+              type: "value",
+              name: "",
+              minInterval: 1, //鍧愭爣杞存槸鏁存暟
+              max: Math.ceil(eval(`Math.max(${data.datay})`) / 5) * 5, //鏁版嵁鏈�澶у�煎姞3
+              interval:
+                (Math.ceil(eval(`Math.max(${data.datay})`) / 5) * 5) / 5,
+              position: "left",
+              axisLine: {
+                show: true,
+                lineStyle: {
+                  color: lineColor,
+                },
+              },
+              nameTextStyle: {
+                color: "#00FFFF",
+              },
+              splitLine: {
+                show: true,
+                lineStyle: {
+                  // 浣跨敤娣辨祬鐨勯棿闅旇壊
+                  color: lineColor,
+                },
+              },
+              axisTick: {
+                show: false,
+              },
+              axisLabel: {
+                textStyle: {
+                  color: "#9B9B9B",
+                },
+                formatter: "",
+              },
+            },
+            {
+              type: "value",
+              name: "",
+              // min: data.yAxis[0].min?data.yAxis.min:0,
+              minInterval: 1, //鍧愭爣杞存槸鏁存暟
+              max: Math.ceil(eval(`Math.max(${data.datay2})`) / 5) * 5, //鏁版嵁鏈�澶у�煎姞3
+              interval:
+                (Math.ceil(eval(`Math.max(${data.datay2})`) / 5) * 5) / 5,
+              position: "right",
+              axisLine: {
+                show: true,
+                lineStyle: {
+                  color: lineColor,
+                },
+              },
+              nameTextStyle: {
+                color: "#00FFFF",
+              },
+              splitLine: {
+                show: true,
+                lineStyle: {
+                  // 浣跨敤娣辨祬鐨勯棿闅旇壊
+                  color: lineColor,
+                },
+              },
+              axisTick: {
+                show: false,
+              },
+              axisLabel: {
+                textStyle: {
+                  color: "#9B9B9B",
+                },
+                formatter: "",
+              },
+            },
+          ],
+          series: [
+            {
+              type: "pictorialBar",
+              name: "姝e搧鏁伴噺",
+              symbol: spirit,
+              symbolRepeat: true,
+              symbolMargin: "25%",
+              symbolClip: true,
+              symbolSize: [17, 4],
+              barCategoryGap: "40%",
+              data: data.datay,
+            },
+            {
+              type: "pictorialBar",
+              barGap: "10%",
+              name: "娆″搧鏁伴噺",
+              symbol: spirit,
+              symbolRepeat: true,
+              symbolMargin: "25%",
+              symbolClip: true,
+              symbolSize: [17, 4],
+              data: data.datay2,
+            },
+          ],
+        };
+        this.chartTimer = setInterval(function () {
+          // 姣忔鍚戝乏婊戝姩涓�涓紝鏈�鍚庝竴涓粠澶村紑濮嬨��
+          if (option.dataZoom[0].endValue == that.chartData.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);
+        }, 3000);
+
+        option && myChart.setOption(option);
+        window.addEventListener("resize", function () {
+          myChart.resize();
+        });
+      } else {
+        option = {};
+        myChart.setOption(option, true);
+      }
+    },
   },
 };
 </script>
 
 <style scoped lang="scss">
-.bar-chart{
-  width:100%;
-  height:calc(100% - 20px);
-  padding:20px 0 0;
-  .bar-contents{
-    width:100%;
-    height:calc(100% - 60px);
-    border:1px solid #00FFFF;
+.bar-chart {
+  width: 100%;
+  height: calc(100% - 20px);
+  padding: 20px 0 0;
+  .bar-contents {
+    width: 100%;
+    height: calc(100% - 60px);
+    border: 1px solid #00ffff;
     box-sizing: border-box;
-    .bar-total{
-      width:100%;
-      height:30px;
-      line-height:30px;
-      color:#dcb018;
-      font-size:14px;
-      margin-top:10px;
-      .bar-item{
-        width:50%;
-        text-align:center;
-        float:left;
+    .bar-total {
+      width: 100%;
+      height: 30px;
+      line-height: 30px;
+      color: #dcb018;
+      font-size: 14px;
+      margin-top: 10px;
+      .bar-item {
+        width: 50%;
+        text-align: center;
+        float: left;
       }
     }
-    .chart{
-        width: 100%;
-        height:calc(100% - 40px);
-      }
+    .chart {
+      width: 100%;
+      height: calc(100% - 40px);
+    }
   }
 }
 </style>

--
Gitblit v1.8.0