liuying
2024-10-16 9fd3f7927d22e5f161b4a6e8b50717cc55b040c4
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
<template>
  <div class="box-container" id="echarts2"></div>
</template>
        
        <script>
let timer = null;
export default {
  data() {
    return {
      option: {},
      myChart: {},
      currentIndex: -1,
    };
  },
  mounted() {
    this.myChart = this.$echarts.init(document.getElementById("echarts2"));
    this.option = {
      legend: {
        orient: "vertical",
        bottom: '10%',
        right: '6%',
        textStyle:{
            color:'#fff'
        },
        itemWidth: 5, // 设置图例项的宽度
        data: [
        {
            name: "实际",
            itemStyle: {
              color: "#fff",
            },
          },
          {
            name: "目标",
            itemStyle: {
              color: "#01afba",
            },
          },
          
        ],
      },
      radar: {
        center:['43%','55%'],
        radius:'65%',
        indicator: [
          { name: "人", max: 100, color: "#fff" },
          { name: "环", max: 100, color: "#fff" },
          { name: "法", max: 100, color: "#fff" },
          { name: "料", max: 100, color: "#fff" },
          { name: "机", max: 100, color: "#fff" },
        ],
        splitNumber: 0,
        axisLine: {
          show: false,
        },
        axisName:{
            padding:-10
        }
 
        // splitArea:{
        //   areaStyle:{
        //     color:'#fff'
        //   }
        // }
      },
      series: [
        {
          name: "Budget vs spending",
          type: "radar",
          data: [
            {
              value: [90, 90, 90, 90, 90],
              name: "实际",
              lineStyle: {
                color: "#fff",
                opacity: 0,
              },
              areaStyle: {
                color: "#fff",
              },
            },
            {
              value: [100, 100, 100, 100, 100],
              name: "目标",
              lineStyle: {
                color: "#01afba",
                opacity: 0,
              },
              areaStyle: {
                color: "#01afba",
              },
            },
          ],
          symbol: "none",
        },
      ],
    };
    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>
</style>