schangxiang@126.com
2025-01-02 d021a6ed089cd06fa460c0e0e303261173fdc16a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<template>
    <div class="box-container echarts3Box" id="echarts3"></div>
</template>
      
      <script>
let timer = null;
export default {
  props: {
    qualityData: {
      type: Array,
      default: () =>[],
    },
  },
  data() {
    return {
      option: {
      xAxis: {
        show: false,
        boundaryGap: false,
        type: "category",
        data: [],
      },
      grid: {
        left: 33,
        right: 33,
        top: 55,
        bottom:5,
      },
      yAxis: {
        show: false,
        type: "value"
      },
      series: [
        {
          data: [],
          type: "line",
          //   symbol:'none',
          // symbolSize: 0,
          lineStyle: {
            color: "#7b8fe6",
          },
          itemStyle: {
            normal: {
              label: {
                show: true,
               
                color: "#7b8fe6",
              },
            },
          },
          label: {
            show: true,
          },
        },
      ],
    },
      myChart: {},
      currentIndex: -1,
    };
  },
  watch:{
    qualityData(val){
      let xData=[],yData=[];
      val.forEach(item => {
        xData.push(item.workPieceID)
        yData.push(item.qualityDataVaule)
      });
      this.$set(this.option.xAxis,'data',xData)
      this.$set(this.option.series[0],'data',yData)
      this.myChart.setOption(this.option);
    }
  },
  mounted() {
    this.myChart = this.$echarts.init(document.getElementById("echarts3"));
    this.myChart.setOption(this.option);
    const that=this
    window.addEventListener('resize',()=>{
      that.myChart.resize();
    })
    // this.defineEvent();
    // this.selectPie();
    // timer = setInterval(this.selectPie, 1500);
  },
  methods: {
    selectPie() {
      let dataLen = this.option.series[0].data.length;
      this.currentIndex = (this.currentIndex + 1) % dataLen;
      this.hignLightPie();
    },
    // 轮播点亮饼图
    hignLightPie() {
      const dataPie = this.option.series[0].data;
      // 熄灭所有扇形区域
      for (var index in dataPie) {
        this.myChart.dispatchAction({
          type: "downplay",
          seriesIndex: 0,
          dataIndex: index,
        });
      }
 
      // 点亮当前扇形区域
      this.myChart.dispatchAction({
        type: "highlight",
        seriesIndex: 0,
        dataIndex: this.currentIndex,
      });
    },
 
    // 鼠标触摸轮播悬停事件
    defineEvent() {
      // 鼠标移出轮播继续
      this.myChart.on("mouseout", () => {
        if (timer) clearInterval(timer);
        timer = setInterval(this.selectPie, 1500);
      });
 
      // 鼠标进入轮播悬停
      this.myChart.on("mouseover", (params) => {
        clearInterval(timer);
        this.currentIndex = params.dataIndex;
        this.hignLightPie();
      });
 
      // 鼠标移入legend轮播悬停
      this.myChart.getZr().on("mouseover", (event) => {
        const legendDataIndex = event.topTarget.parent.__legendDataIndex; // 每个legend的index
        clearInterval(timer);
        this.currentIndex = legendDataIndex;
        this.hignLightPie();
      });
 
      // 鼠标移出legend轮播继续
      this.myChart.getZr().on("mouseout", () => {
        if (timer) clearInterval(timer);
        timer = setInterval(this.selectPie, 1500);
      });
    },
  },
};
</script>
      
      <style>
   .echarts3Box{
    height: 150px !important;
    /* background-color: #040d3d; */
    /* width: 96%; */
    margin: 0 auto;
   }
</style>