liuying
2025-09-24 6efa5f6ca7536a37e3af3592bb42db63bcb8371d
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<template>
  <!-- 本班/本月产量统计 -->
  <div class="box-container box4" id="echarts4"></div>
</template>
 
<script>
let timer = null;
export default {
  props: {
    produceStatisData: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      option: {},
      myChart: {},
      currentIndex: -1,
      data1: [],
      data2: [{ actualData: 2782, planData: 11128 }],
    };
  },
  watch: {
    produceStatisData(val) {
      // 测试用:
      // val.currentShiftProduceNum = 280;
      // val.currentShiftPlanNum = 300;
 
      // 当前班组实际生产数量 currentShiftProduceNum
      // 当前班组计划生产数量 currentShiftPlanNum
      var num1 = val.currentShiftProduceNum; //实际生产数量
      var num2 = val.currentShiftPlanNum - val.currentShiftProduceNum; //计划生产数量
      if (val.currentShiftPlanNum == 0) {
        //分母为0 显示0%
        num1 = 0;
        num2 = 10;
      }
      this.$set(this.option.series[0], "data", [
        // { value: 1 },  //实际生产数量 1/ (9+1) = 10%
        // { value: 9 },
        {
          value: num1,
        }, //实际生产数量
        {
          value: num2,
        },
      ]);
      var num3 = val.currentMonthProduceNum;
      var num4 = val.currentMonthPlanNum - val.currentMonthProduceNum;
      if (val.currentMonthPlanNum == 0) {
        //分母为0 显示0%
        num3 = 0;
        num4 = 10;
      }
      this.$set(this.option.series[1], "data", [
        { value: num3 },
        { value: num4 },
      ]);
 
      this.myChart.setOption(this.option);
      this.hignLightPie();
    },
  },
  mounted() {
    this.myChart = this.$echarts.init(document.getElementById("echarts4"));
    this.option = {
      color: ["#00f6fe", "transparent"],
      // 插入背景图
      //    graphic: [
      //   {
      //     type: "image",
      //     id: "background1",
      //     left: "13px", // 根据环形图的位置调整
      //     top: "61px", // 根据环形图的位置调整
      //     z: -10,
      //     bounding: "raw",
      //     origin: [0, 0],
      //     style: {
      //       image: require(`@/assets/images/quan.png`), // 第一个环形图的背景图片路径
      //       width: 100,
      //       height: 100,
      //     },
      //   },
      //   {
      //     type: "image",
      //     id: "background2",
      //     left: "131px", // 根据环形图的位置调整
      //     top: "61px", // 根据环形图的位置调整
      //     z: -10,
      //     bounding: "raw",
      //     origin: [0, 0],
      //     style: {
      //       image: require(`@/assets/images/quan.png`), // 第一个环形图的背景图片路径
      //       width: 100,
      //       height: 100,
      //     },
      //   },
      // ],
      series: [
        {
          name: "Access From",
          type: "pie",
          // padAngle: 5, //环与环之间的间隙
          radius: ["29%", "36%"], //环变细
          center: ["25%", "49%"],
          // avoidLabelOverlap: false,
          label: {
            show: false,
            position: "center",
            formatter: function (params) {
              return params.percent < 1
                ? params.percent + "%"
                : Math.floor(params.percent) + "%"; // 四舍五入到整数
            },
            color: "#fff",
            fontSize: 12,
          },
          emphasis: {
            //饼图中间的字体大小
            scale: false,
            label: {
              show: true,
              fontSize: 22,
              color: "#19d8d0",
              fontWeight: "normal",
            },
          },
          labelLine: {
            show: false,
          },
          itemStyle: {
            borderRadius: 3,
            borderColor: "transparent",
            borderWidth: 10,
          },
          data: [],
        },
        {
          name: "Access From",
          type: "pie",
          // padAngle: 5, //环与环之间的间隙
          // radius: ["25%", "40%"],
          radius: ["29%", "36%"], //环变细
          center: ["74%", "49%"],
          // avoidLabelOverlap: false,
          label: {
            show: false,
            position: "center",
            formatter: function (params) {
              return params.percent < 1
                ? params.percent + "%"
                : Math.floor(params.percent) + "%"; // 四舍五入到整数
            },
            color: "#fff",
            fontSize: 12,
          },
          itemStyle: {
            borderRadius: 3,
            borderColor: "transparent",
            borderWidth: 10,
          },
          emphasis: {
            scale: false,
            label: {
              show: true,
              fontSize: 22,
              color: "#19d8d0",
              fontWeight: "normal",
            },
          },
          labelLine: {
            show: false,
          },
          data: [],
        },
      ],
    };
    this.myChart.setOption(this.option);
    const that = this;
    window.addEventListener("resize", () => {
      that.myChart.resize();
    });
    // this.getData();
    this.defineEvent();
    // this.selectPie();
    this.hignLightPie();
    // timer = setInterval(this.selectPie, 1500);
  },
  methods: {
    // getData() {
    //   this.data1 = [{ actualData: 144, planData: 288 }];
    //   this.$set(this.option.series[0], "data", [
    //     { value: this.data1[0].actualData },
    //     { value: this.data1[0].planData - this.data1[0].actualData },
    //   ]);
    //   this.$set(this.option.series[1], "data", [
    //     { value: this.data2[0].actualData },
    //     { value: this.data2[0].planData - this.data2[0].actualData },
    //   ]);
    //   console.log(this.option.series[0].data);
    //   this.myChart.setOption(this.option);
    // },
    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: "downplay",
          seriesIndex: 1,
          dataIndex: index,
        });
      }
 
      // 点亮当前扇形区域
      this.myChart.dispatchAction({
        type: "highlight",
        seriesIndex: 0,
        dataIndex: 0,
      });
 
      this.myChart.dispatchAction({
        type: "highlight",
        seriesIndex: 1,
        dataIndex: 0,
      });
    },
 
    // 鼠标触摸轮播悬停事件
    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>
#echarts4 {
  transform: scaleY(2);
}
</style>