guanqb
2024-01-02 432456dea4e9f370f76a42f7b341596012c3c38f
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
<template>
    <div class="echart-box" :id="elementId"></div>
</template>
 
<script>
 
export default {
    data () {
        return {
            elementId: ''
        }
    },
 
    props: {
        params: {
            type: Object
        }
    },
 
    created () {
        this.elementId = this.uuid()
    },
 
    mounted () {
        this.$nextTick(() => {
            this.initEcharts()
        })
    },
 
    methods: {
        uuid () {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                var r = Math.random() * 16 | 0,
                    v = c == 'x' ? r : (r & 0x3 | 0x8)
                return v.toString(16)
            })
        },
 
        initEcharts () {
            const that = this
            const myChart = that.$echarts.init(document.getElementById(that.elementId))
 
            var percent = this.params.value //百分数
            var color_percent0 = '',
                color_percent100 = '',
                dotArray = []
 
 
            calculateDot(percent)//80%显示4个点,
 
 
            function calculateDot (data) {
                if (data <= 20) {
                    dotArray.push(80)
                    color_percent0 = 'rgba(12,255,0,1)'
                    color_percent100 = 'rgba(12,255,0,.3)'
                } else if (data > 20 && data <= 40) {
                    dotArray.push(...[80, 80])
                    color_percent0 = 'rgba(12,255,0,1)'
                    color_percent100 = 'rgba(12,255,0,.3)'
                } else if (data > 40 && data <= 60) {
                    dotArray.push(...[80, 80, 80])
                    color_percent0 = 'rgba(255,123,0,1)'
                    color_percent100 = 'rgba(255,123,0,.3)'
                } else if (data > 60 && data <= 80) {
                    dotArray.push(...[80, 80, 80, 80])
                    color_percent0 = 'rgba(255,0,36,1)'
                    color_percent100 = 'rgba(255,0,36,.3)'
                } else if (data > 80 && data <= 100) {
                    dotArray.push(...[80, 80, 80, 80, 80])
                    color_percent0 = 'rgba(255,0,36,1)'
                    color_percent100 = 'rgba(255,0,36,.3)'
                }
 
            }
 
            const option = {
                backgroundColor: '#000',
                title: {
                    left: 'center',
                    top: '68%',//字体的位置
                    text: this.params.type,
                    textStyle: {
                        fontWeight: 'normal',
                        color: '#FFF',
                        fontSize: 12
                    },
                    subtextStyle: {//副标题的文字的样式
                        fontWeigh: 'bold',
                        fontSize: 12,
                        color: '#3ea1ff'
                    },
 
                },
                series: [
                    {
                        type: 'pie',
                        radius: ['50%', '70%'],
                        avoidLabelOverlap: false,
                        startAngle: 225,
                        color: [{
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0.4,
                            y2: 1,
                            colorStops: [{
                                offset: 0,
                                color: color_percent0 // 0% 处的颜色
                            }, {
                                offset: 1,
                                color: color_percent100 // 100% 处的颜色
                            }],
                            globalCoord: false // 缺省为 false
                        }, 'none'],
                        hoverAnimation: false,//是否开启 hover 在扇区上的放大动画效果。
                        legendHoverLink: false,//是否启用图例 hover 时的联动高亮。
                        label: {
                            normal: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                show: true,
                                textStyle: {
                                    fontSize: 12,
                                    fontWeight: 'bold'
                                }
                            }
                        },
                        labelLine: {
                            normal: {
                                "show": false
                            }
                        },
                        data: [{
                            value: 75,
                            name: '1'
                        }, {
                            value: 25,
                            name: '2'
                        }]
                    },
                    {
                        type: 'pie',
                        radius: ['48%', '47%'],
                        avoidLabelOverlap: false,//是否启用防止标签重叠策略
                        startAngle: 225,
 
                        hoverAnimation: false,
                        legendHoverLink: false,
                        label: {
                            normal: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                show: true,
                                textStyle: {
                                    fontSize: 12,
                                    fontWeight: 'bold'
                                }
                            }
                        },
                        labelLine: {
                            normal: {
                                show: false
                            }
                        },
                        data: [{
                            value: 75,
                            name: '1'
                        }, {
                            value: 25,
                            name: '2'
                        }]
                    },
                    {
                        type: 'pie',
                        radius: ['50%', '70%'],
                        avoidLabelOverlap: false,
                        startAngle: 315,
                        color: ['rgba(34,34,34,.9)', "#ff7a00", "transparent"],
                        hoverAnimation: false,
                        legendHoverLink: false,
                        clockwise: false,//饼图的扇区是否是顺时针排布。
                        itemStyle: {
                            normal: {
                                borderColor: "transparent",
                                borderWidth: "20"
                            },
                            emphasis: {
                                borderColor: "transparent",
                                borderWidth: "20"
                            }
                        },
                        z: 10,
                        label: {
                            normal: {
                                show: false,
                                position: 'center'
                            },
 
                        },
                        labelLine: {
                            normal: {
                                show: false
                            }
                        },
                        data: [{
                            value: (100 - percent) * 270 / 360,
 
                            label: {
                                normal: {
                                    formatter: percent + '%',
                                    position: 'center',
                                    show: true,
                                    textStyle: {
                                        fontSize: 12,
                                        fontWeight: 'normal',
                                        color: '#fff'
                                    }
                                }
                            },
                            name: ''
                        }, {
                            value: 1,
                            name: ''
                        }, {
                            value: 100 - (100 - percent) * 270 / 360,
                            name: ''
                        }]
                    },
                ]
            }
 
            myChart.setOption(option)
        }
    },
}
</script>
 
<style lang="scss" scoped>
.echart-box {
    height: 100%;
}
</style>