Blame view

src/components/allPieChart.vue 8.09 KB
e00e4982   liuqimichale   道闸 诱导屏
1
2
3
4
5
6
  <template>
    <div :class="className" :style="{height:height,width:width}"></div>
  </template>
  
  <script>
  import echarts from 'echarts'
e00e4982   liuqimichale   道闸 诱导屏
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  import {debounce} from '../utils/debounce'
  
  export default {
    name: 'allPieChart',
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
974ee116   liuqimichale   道闸
22
        default: '100%'
e00e4982   liuqimichale   道闸 诱导屏
23
24
25
26
27
28
      },
      autoResize: {
        type: Boolean,
        default: true
      },
      chartData: {
be79dd15   liuqimichale   道闸
29
        type: Array,
e00e4982   liuqimichale   道闸 诱导屏
30
31
32
33
34
35
        required: true
      }
    },
    data() {
      return {
        chart: null,
e00e4982   liuqimichale   道闸 诱导屏
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
      }
    },
    watch: {
      chartData: {
        deep: true,
      }
    },
    mounted() {
      this.initChart()
      if (this.autoResize) {
        this.__resizeHandler = debounce(() => {
          if (this.chart) {
            this.chart.resize()
          }
        }, 100)
        window.addEventListener('resize', this.__resizeHandler)
      }
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      if (this.autoResize) {
        window.removeEventListener('resize', this.__resizeHandler)
      }
e00e4982   liuqimichale   道闸 诱导屏
61
62
63
64
      this.chart.dispose()
      this.chart = null
    },
    methods: {
be79dd15   liuqimichale   道闸
65
      setOptions(data) {
e00e4982   liuqimichale   道闸 诱导屏
66
        this.chart.setOption({
e00e4982   liuqimichale   道闸 诱导屏
67
68
69
70
          tooltip: {
            trigger: 'item',
            formatter: "{b} : {c} ({d}%)"
          },
66faa378   liuqimichale   道闸 诱导屏
71
          series: [
be79dd15   liuqimichale   道闸
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
            {
              type: 'pie',
              radius: ['30%', '31%'],
              center: ['50%', '50%'],
              hoverAnimation:false,
              tooltip: {
                show:false
              },
              label: {
                show: false
              },
              lableLine: {
                show: false
              },
              data: [
                {
                  value: 0,
                },
                {
                  value: 55,
                  itemStyle: {
                    normal: {
                      color: 'rgba(89,170,247,.3)'
                    }
                  }
                },
  
              ]
            },
            {
              type: 'pie',
              radius: ['40%', '41%'],
              center: ['50%', '50%'],
              hoverAnimation:false,
              tooltip: {
                show:false
              },
              label: {
                show: false
              },
              lableLine: {
                show: false
              },
              data: [
                {
                  value: 0,
                },
                {
                  value: 55,
                  itemStyle: {
                    normal: {
                      color: 'rgba(89,170,247,.3)'
                    }
                  }
                },
  
              ]
            },
            {
              type: 'pie',
              radius: ['50%', '51%'],
              center: ['50%', '50%'],
              hoverAnimation:false,
              tooltip: {
                show:false
              },
              label: {
                show: false
              },
              lableLine: {
                show: false
              },
              data: [
                {
                  value: 0,
                },
                {
                  value: 55,
                  itemStyle: {
                    normal: {
                      color: 'rgba(89,170,247,.3)'
                    }
                  }
                },
  
              ]
            },
            {
              type: 'pie',
              radius: ['60%', '61%'],
              center: ['50%', '50%'],
              hoverAnimation:false,
              tooltip: {
                show:false
              },
              label: {
                show: false
              },
              lableLine: {
                show: false
              },
              data: [
                {
                  value: 0,
                },
                {
                  value: 55,
                  itemStyle: {
                    normal: {
                      color: 'rgba(89,170,247,.3)'
                    }
                  }
                },
  
              ]
            },
            {
              type: 'pie',
              radius: ['70%', '71%'],
              center: ['50%', '50%'],
              hoverAnimation:false,
              tooltip: {
                show:false
              },
              label: {
                show: false
              },
              lableLine: {
                show: false
              },
              data: [
                {
                  value: 0,
                },
                {
                  value: 55,
                  itemStyle: {
                    normal: {
                      color: 'rgba(89,170,247,.3)'
                    }
                  }
                },
  
              ]
            },
            {
              type: 'pie',
              radius: ['80%', '81%'],
              center: ['50%', '50%'],
              hoverAnimation:false,
              tooltip: {
                show:false
              },
              label: {
                show: false
              },
              lableLine: {
                show: false
              },
              data: [
                {
                  value: 0,
                },
                {
                  value: 55,
                  itemStyle: {
                    normal: {
                      color: 'rgba(89,170,247,.3)'
                    }
                  }
                },
  
              ]
            },
            {
              type: 'pie',
              radius: ['90%', '91%'],
              center: ['50%', '50%'],
              hoverAnimation:false,
              tooltip: {
                show:false
              },
              label: {
                show: false
              },
              lableLine: {
                show: false
              },
              data: [
                {
                  value: 0,
                },
                {
                  value: 55,
                  itemStyle: {
                    normal: {
                      color: 'rgba(89,170,247,.3)'
                    }
                  }
                },
  
              ]
            },
  
66faa378   liuqimichale   道闸 诱导屏
276
277
  
            {
e00e4982   liuqimichale   道闸 诱导屏
278
279
280
281
282
283
            name: '内环',
            type: 'pie',
            silent: true,
            clockWise: true,
            hoverAnimation: false,
            animationType: 'scale',
66faa378   liuqimichale   道闸 诱导屏
284
            radius: ['10%','16%'],
e00e4982   liuqimichale   道闸 诱导屏
285
286
287
288
289
290
291
292
293
294
295
296
297
            center: ['50%', '50%'],
            label: {
              normal: {
                position: 'center'
              }
            },
            data: [{
              value: 100,
              itemStyle: {
                normal: {
                  color: {
                    colorStops: [{
                      offset: 0,
66faa378   liuqimichale   道闸 诱导屏
298
                      color: '#157ADB' // 0% 处的颜色
e00e4982   liuqimichale   道闸 诱导屏
299
300
                    }, {
                      offset: 1,
66faa378   liuqimichale   道闸 诱导屏
301
                      color: '#157ADB' // 100% 处的颜色
e00e4982   liuqimichale   道闸 诱导屏
302
303
304
305
306
307
308
309
310
311
                    }]
                  }
                }
              }
            }]
          },
  
            {
              name: '半径模式',
              type: 'pie',
be79dd15   liuqimichale   道闸
312
              radius: ['20%', '80%'],
e00e4982   liuqimichale   道闸 诱导屏
313
              center: ['50%', '50%'],
974ee116   liuqimichale   道闸
314
              hoverAnimation:false,
e00e4982   liuqimichale   道闸 诱导屏
315
316
317
318
319
320
321
              roseType: 'radius',
              label: {
                show: false
              },
              lableLine: {
                show: false
              },
66faa378   liuqimichale   道闸 诱导屏
322
              data: [
e00e4982   liuqimichale   道闸 诱导屏
323
                {
be79dd15   liuqimichale   道闸
324
                  value: data[0],
66faa378   liuqimichale   道闸 诱导屏
325
                  name: '诱导屏',
e00e4982   liuqimichale   道闸 诱导屏
326
327
328
329
330
                  itemStyle: {
                    normal: {
                      color: {
                        colorStops: [{
                          offset: 0,
66faa378   liuqimichale   道闸 诱导屏
331
                          color: '#FFBA00' // 0% 处的颜色
e00e4982   liuqimichale   道闸 诱导屏
332
333
                        }, {
                          offset: 1,
66faa378   liuqimichale   道闸 诱导屏
334
                          color: '#FF8100' // 100% 处的颜色
e00e4982   liuqimichale   道闸 诱导屏
335
336
337
338
339
340
                        }]
                      },
                    }
                  }
                },
                {
be79dd15   liuqimichale   道闸
341
                  value: data[1],
66faa378   liuqimichale   道闸 诱导屏
342
                  name: '道闸',
e00e4982   liuqimichale   道闸 诱导屏
343
344
345
346
347
                  itemStyle: {
                    normal: {
                      color: {
                        colorStops: [{
                          offset: 0,
66faa378   liuqimichale   道闸 诱导屏
348
                          color: '#00CAFE' // 0% 处的颜色
e00e4982   liuqimichale   道闸 诱导屏
349
350
                        }, {
                          offset: 1,
66faa378   liuqimichale   道闸 诱导屏
351
                          color: '#2772F4' // 100% 处的颜色
e00e4982   liuqimichale   道闸 诱导屏
352
353
354
355
                        }]
                      },
                    }
                  }
66faa378   liuqimichale   道闸 诱导屏
356
357
                },
  
e00e4982   liuqimichale   道闸 诱导屏
358
359
              ],
              animationType: 'scale',
974ee116   liuqimichale   道闸
360
              animationEasing: 'elasticOut'
e00e4982   liuqimichale   道闸 诱导屏
361
362
363
364
365
366
            }
  
          ]
        })
      },
      initChart() {
974ee116   liuqimichale   道闸
367
        this.chart = echarts.init(this.$el)
e00e4982   liuqimichale   道闸 诱导屏
368
369
370
371
372
        this.setOptions(this.chartData)
      }
    }
  }
  </script>