he wei
2023-02-10 5a3753b8a6fbb346510c20436cb9733dd137e1e5
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
<template>
    <div class="e-chart-root" :class="{'full-screen': fullScreenState}">
        <div class="e-chart-container">
            <div class="e-chart" :id="id" :ref="id"></div>
        </div>
    </div>
</template>
 
<script>
// 引入 ECharts 主模块
import ECharts from "echarts/lib/echarts";
//引入仪表盘
import "echarts/lib/chart/gauge";
import "echarts/lib/chart/pie"
//引入提示框
import "echarts/lib/component/tooltip";
//引入标题
import "echarts/lib/component/title";
//引入图例标志
import "echarts/lib/component/legend";
//区域缩放
import "echarts/lib/component/dataZoom";
import "echarts/lib/component/graphic"
 
export default {
    name: "GaugeCircleChart",
    props: {
        id: {
            type: String,
            default: ""
        }
    },
    data() {
        return {
            fullScreenState: false,
        }
    },
    methods: {
        getOption(opt) {
            let option = {
                title: {
                    show: false,
                    text: '任务进度',
                    x: '50%',
                    y: '57%',
                    z: 8,
                    textAlign: 'center',
                    textStyle: {
                        color: '#f1f7fe',
                        fontSize: 20,
                        fontWeight: 'normal'
                    },
 
                },
                series: [
                    {
                        name: "内部(环形)进度条",
                        type: "gauge",
                        radius: '50%',
                        startAngle: 90,
                        endAngle: 269.9,
                        splitNumber: 10,
                        axisLine: {
                            lineStyle: {
                                color: [
                                    [1, '#fdda9a'],
                                    [1, "#FFFFFF"]
                                ],
                                width: 8
                            }
                        },
                        axisLabel: {
                            show: false,
                        },
                        axisTick: {
                            show: false,
                        },
                        splitLine: {
                            show: false,
                        },
                        pointer: {
                            show: false,
                        },
                    },
                    {
                        name: '外部刻度',
                        type: 'gauge',
                        radius: '40%',
                        min: 0, //最小刻度
                        max: 100, //最大刻度
                        splitNumber: 10, //刻度数量
                        startAngle: 0,
                        endAngle: 359.9,
                        axisLine: {
                            show: true,
                            // 仪表盘刻度线
                            lineStyle: {
                                width: 2,
                                color: [
                                    [1, '#FFFFFF']
                                ]
                            }
                        },
                        //仪表盘文字
                        axisLabel: {
                            show: false,
                        }, //刻度标签。
                        axisTick: {
                            show: true,
                            splitNumber: 7,
                            lineStyle: {
                                color: '#fdda9a', //用颜色渐变函数不起作用
                                width: 2,
                            },
                            length: -6
                        }, //刻度样式
                        splitLine: {
                            show: false,
                        }, //分隔线样式
                        detail: {
                            show: false
                        },
                        pointer: {
                            show: false
                        }
                    },
                    /*内部*/
                    {
                        type: 'pie',
                        radius: ['0', '40%'],
                        center: ['50%', '50%'],
                        z: 8,
                        hoverAnimation: false,
                        data: [{
                            name: '检查进度',
                            value: 0,
                            itemStyle: {
                                normal: {
                                    color: new ECharts.graphic.LinearGradient(0, 0, 0, 1, [{
                                        offset: 0,
                                        color: '#fdda9a'
                                    }, {
                                        offset: 1,
                                        color: '#ff7c2c'
                                    }])
                                }
                            },
                            label: {
                                normal: {
                                    formatter: [
                                        "{value|"+opt.value+"}",
                                        "{name|"+opt.name+"}",
                                    ].join("\n"),
                                    color: '#FFFFFF',
                                    fontSize: 16,
                                    fontWeight: "bold",
                                    position: 'center',
                                    show: true,
                                    rich: {
                                        name: {
                                            color: opt.nameColor,
                                        },
                                        value:  {
                                            fontSize: 40,
                                            color: opt.valueColor,
                                        }
                                    },
                                }
                            },
                            labelLine: {
                                show: false
                            }
                        }],
                    },
                ]
            };
            return option;
        },
        setOption(opt) {
            let option = this.getOption(opt);
            // 清理画布
            this.$G.chartManage.get(this.id).clear();
            // 设置配置项
            this.$G.chartManage.get(this.id).setOption(option);
        },
        resize() {
            this.$G.chartManage.get(this.id).resize();
        },
        fullScreen() {
            this.fullScreenState = this.fullScreenState?false:true;
            this.$nextTick(()=>{
                // 重置大小
                this.$G.chartManage.get(this.id).resize();
            });
        }
    },
    mounted() {
        // 基于准备好的dom,初始化echarts实例
        let chart = ECharts.init(this.$refs[this.id], 'transparent');
        // 将图表添加到图表管理
        this.$G.chartManage.set(this.id, chart);
        // 设置配置项
        this.setOption({
            value: 10,
            name: '纹波峰值',
            valueColor: "#fff",
            nameColor: "#000",
        });
    }
}
</script>
 
<style scoped>
.e-chart-root,
.e-chart-container,
.e-chart {
    height: 100%;
    box-sizing: border-box;
}
.e-chart-root.full-screen .e-chart-container{
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-size: 100% 100%;
    z-index: 9999;
}
</style>