liuying
2025-04-28 0630126012170da25291d55f0a1bd3130e64f434
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
<template>
  <!-- 本班/本月产量统计 -->
  <div class="box-container box4" id="echarts4"></div>
</template>
 
<script>
let timer = null;
import * as echarts from "echarts";
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"));
    var value = 60;
    var value2 = 15;
    let data1 = [
      {
        value: value,
        name: "",
        itemStyle: {
          normal: {
            color: "#62fbf8",
          },
        },
      },
      {
        value: 100 - value,
        name: "",
        label: {
          normal: {
            show: false,
          },
        },
        itemStyle: {
          normal: {
            color: "rgba(0,0,0,0)",
          },
        },
      },
    ];
 
    let data2 = [
      {
        value: value2,
        name: "",
        itemStyle: {
          normal: {
            color: "rgb(105,206,195)",
          },
        },
      },
      {
        value: 100 - value2,
        name: "",
        label: {
          normal: {
            show: false,
          },
        },
        itemStyle: {
          normal: {
            color: "rgba(0,0,0,0)",
          },
        },
      },
    ];
 
    this.option = {
      color: ["#00f6fe", "rgba(5, 19, 96, 0.5)"],
      // 插入背景图
      //    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: "左-数据",
          type: "pie",
          // radius: ['65%', '75%'],
          radius: ["29%", "36%"], //环变细
          center: ["25%", "49%"],
          silent: true,
          // clockwise: false,
          startAngle: 90,
          z: 1,
          zlevel: 0,
          label: {
            normal: {
              position: "center",
            },
          },
          data: data1,
        },
        {
          name: "左-中间渐变",
          type: "pie",
          startAngle: 90,
          z: 20,
          zlevel: 20,
          radius: "28%",
          hoverAnimation: false,
          center: ["25%", "49%"],
 
          // zlevel: 2,
          itemStyle: {
            normal: {
              labelLine: {
                show: false,
              },
              color: new echarts.graphic.RadialGradient(0.5, 0.5, 1, [
                {
                  offset: 1,
                  color: "rgba(55,70,130, 1)",
                },
                {
                  offset: 0,
                  color: "rgba(55,70,130, 0)",
                },
              ]),
              shadowBlur: 10,
              // shadowColor: 'rgba(55,70,130, 1)'
            },
          },
          data: [
            {
              value: 100,
            },
          ],
        },
        {
          name: "左-刻度间隔",
          z: 2,
          // zlevel: 1,
          type: "gauge",
          radius: "57%",
          center: ["25%", "49%"],
          startAngle: 20,
          endAngle: -360,
          splitNumber: 10,
          hoverAnimation: true,
          axisTick: {
            show: true,
            splitNumber: 1,
            length: 14, //刻度长度
            // Distance: 40, //刻度间隔距离
            lineStyle: {
              width: 5,
              color: new echarts.graphic.LinearGradient(
                0,
                0,
                0,
                1,
                [
                  {
                    offset: 0,
                    color: "rgba(8, 52, 106, 0.039)", // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "rgba(8, 52, 106, 0.239)", // 100% 处的颜色
                  },
                ],
                false
              ),
            },
          },
          splitLine: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          pointer: {
            show: false,
          },
          axisLine: {
            lineStyle: {
              opacity: 0,
            },
          },
          detail: {
            show: false,
          },
          data: [100],
        },
 
        // 右侧
        {
          name: "右-数据",
          type: "pie",
          // radius: ['65%', '75%'],
          radius: ["29%", "36%"], //环变细
          center: ["74%", "49%"],
          silent: true,
          // clockwise: false,
          startAngle: 90,
          z: 1,
          zlevel: 0,
          label: {
            normal: {
              position: "center",
            },
          },
          data: data2,
        },
        {
          name: "右-中间渐变",
          type: "pie",
          startAngle: 90,
          radius: "28%",
          hoverAnimation: false,
          center: ["74%", "49%"],
          itemStyle: {
            normal: {
              labelLine: {
                show: false,
              },
              color: new echarts.graphic.RadialGradient(0.5, 0.5, 1, [
                {
                  offset: 1,
                  color: "rgba(55,70,130, 1)",
                },
                {
                  offset: 0,
                  color: "rgba(55,70,130, 0)",
                },
              ]),
              shadowBlur: 10,
              // shadowColor: 'rgba(55,70,130, 1)'
            },
          },
          data: [
            {
              value: 100,
            },
          ],
        },
        {
          name: "右-刻度间隔",
          z: 2,
          type: "gauge",
          radius: "45%",
          center: ["74%", "49%"],
          startAngle: 90,
          endAngle: -360,
          splitNumber: 10,
          hoverAnimation: true,
          axisTick: {
            show: true,
            splitNumber: 1,
            length: 20,
            lineStyle: {
              width: 10,
              color: "#1183a7",
              shadowColor: "rgb(4,31,62, 0.5)",
            },
          },
          splitLine: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          pointer: {
            show: false,
          },
          axisLine: {
            lineStyle: {
              opacity: 0,
            },
          },
          detail: {
            show: false,
          },
          data: [100],
        },
      ],
    };
    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>