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
| <!--
| 描述: 仪表盘
| 作者: Jack Chen
| 日期: 2020-05-03
| -->
|
| <template>
| <div class="wrap-container sn-container">
| <div class="sn-content">
| <div class="sn-title">仪表盘</div>
| <div class="sn-body">
| <div class="wrap-container">
| <div class="chartsdom" id="chart_gauge"></div>
| </div>
| </div>
| </div>
| </div>
| </template>
|
| <script>
| export default {
| name: "gauge",
| data() {
| return {
| option: null,
| timer: null
| }
| },
| mounted() {
| this.getEchart();
| },
| methods: {
| getEchart() {
| let myChart = echarts.init(document.getElementById('chart_gauge'));
| this.option = {
| tooltip: {
| formatter: '{a} <br/>{c} {b}'
| },
| series: [{
| name: '速度',
| type: 'gauge',
| min: 0,
| max: 220,
| splitNumber: 11,
| // radius: '50%',
| axisLine: { // 坐标轴线
| lineStyle: { // 属性lineStyle控制线条样式
| color: [[0.09, 'lime'], [0.82, '#1e90ff'], [1, '#ff4500']],
| width: 3,
| shadowColor: '#fff', //默认透明
| shadowBlur: 10
| }
| },
| axisLabel: { // 坐标轴小标记
| fontWeight: 'bolder',
| color: '#fff',
| shadowColor: '#fff', //默认透明
| shadowBlur: 10
| },
| axisTick: { // 坐标轴小标记
| length: 15, // 属性length控制线长
| lineStyle: { // 属性lineStyle控制线条样式
| color: 'auto',
| shadowColor: '#fff', //默认透明
| shadowBlur: 10
| }
| },
| splitLine: { // 分隔线
| length: 25, // 属性length控制线长
| lineStyle: { // 属性lineStyle(详见lineStyle)控制线条样式
| width: 3,
| color: '#fff',
| shadowColor: '#fff', //默认透明
| shadowBlur: 10
| }
| },
| pointer: { // 分隔线
| shadowColor: '#fff', //默认透明
| shadowBlur: 5
| },
| title: {
| textStyle: { // 其余属性默认使用全局文本样式,详见TEXTSTYLE
| fontWeight: 'bolder',
| fontSize: 20,
| fontStyle: 'italic',
| color: '#fff',
| shadowColor: '#fff', //默认透明
| shadowBlur: 10
| }
| },
| detail: {
| // backgroundColor: 'rgba(30,144,255,0.8)',
| // borderWidth: 1,
| // borderColor: '#fff',
| // shadowColor: '#fff', //默认透明
| // shadowBlur: 5,
| offsetCenter: [0, '50%'], // x, y,单位px
| textStyle: { // 其余属性默认使用全局文本样式,详见TEXTSTYLE
| fontWeight: 'bolder',
| fontSize: 25,
| color: '#fff'
| }
| },
| data: [{
| value: 40,
| name: 'km/h'
| }]
| }]
| }
|
|
| myChart.setOption(this.option, true);
|
| window.addEventListener('resize', () => {
| myChart.resize();
| });
|
| this.timer = setInterval(() => {
| this.option.series[0].data[0].value = (Math.random()*100).toFixed(2) - 0;
| myChart.setOption(this.option, true);
| },2000);
| }
| },
| beforeDestroy() {
| clearInterval(this.timer);
| }
| };
| </script>
|
| <style lang="scss" scoped>
| .sn-container {
| left: 512px;
| top: 2838px;
| width: 432px;
| height: 400px;
| .chartsdom {
| width: 100%;
| height: 100%;
| }
| }
| </style>
|
|