Blame view

src/components/allPieChart.vue 8.15 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
      }
    },
    watch: {
adf82b69   liuqimichale   调取接口
39
40
41
42
      chartData: function () {
        this.$nextTick(()=>{
          this.initChart()
        })
e00e4982   liuqimichale   道闸 诱导屏
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
      }
    },
    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   道闸 诱导屏
63
64
65
66
      this.chart.dispose()
      this.chart = null
    },
    methods: {
be79dd15   liuqimichale   道闸
67
      setOptions(data) {
e00e4982   liuqimichale   道闸 诱导屏
68
        this.chart.setOption({
e00e4982   liuqimichale   道闸 诱导屏
69
70
71
72
          tooltip: {
            trigger: 'item',
            formatter: "{b} : {c} ({d}%)"
          },
66faa378   liuqimichale   道闸 诱导屏
73
          series: [
be79dd15   liuqimichale   道闸
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
276
277
            {
              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   道闸 诱导屏
278
279
  
            {
e00e4982   liuqimichale   道闸 诱导屏
280
281
282
283
284
285
            name: '内环',
            type: 'pie',
            silent: true,
            clockWise: true,
            hoverAnimation: false,
            animationType: 'scale',
66faa378   liuqimichale   道闸 诱导屏
286
            radius: ['10%','16%'],
e00e4982   liuqimichale   道闸 诱导屏
287
288
289
290
291
292
293
294
295
296
297
298
299
            center: ['50%', '50%'],
            label: {
              normal: {
                position: 'center'
              }
            },
            data: [{
              value: 100,
              itemStyle: {
                normal: {
                  color: {
                    colorStops: [{
                      offset: 0,
66faa378   liuqimichale   道闸 诱导屏
300
                      color: '#157ADB' // 0% 处的颜色
e00e4982   liuqimichale   道闸 诱导屏
301
302
                    }, {
                      offset: 1,
66faa378   liuqimichale   道闸 诱导屏
303
                      color: '#157ADB' // 100% 处的颜色
e00e4982   liuqimichale   道闸 诱导屏
304
305
306
307
308
309
310
311
312
313
                    }]
                  }
                }
              }
            }]
          },
  
            {
              name: '半径模式',
              type: 'pie',
be79dd15   liuqimichale   道闸
314
              radius: ['20%', '80%'],
e00e4982   liuqimichale   道闸 诱导屏
315
              center: ['50%', '50%'],
974ee116   liuqimichale   道闸
316
              hoverAnimation:false,
e00e4982   liuqimichale   道闸 诱导屏
317
318
319
320
321
322
323
              roseType: 'radius',
              label: {
                show: false
              },
              lableLine: {
                show: false
              },
66faa378   liuqimichale   道闸 诱导屏
324
              data: [
e00e4982   liuqimichale   道闸 诱导屏
325
                {
be79dd15   liuqimichale   道闸
326
                  value: data[0],
66faa378   liuqimichale   道闸 诱导屏
327
                  name: '诱导屏',
e00e4982   liuqimichale   道闸 诱导屏
328
329
330
331
332
                  itemStyle: {
                    normal: {
                      color: {
                        colorStops: [{
                          offset: 0,
66faa378   liuqimichale   道闸 诱导屏
333
                          color: '#FFBA00' // 0% 处的颜色
e00e4982   liuqimichale   道闸 诱导屏
334
335
                        }, {
                          offset: 1,
66faa378   liuqimichale   道闸 诱导屏
336
                          color: '#FF8100' // 100% 处的颜色
e00e4982   liuqimichale   道闸 诱导屏
337
338
339
340
341
342
                        }]
                      },
                    }
                  }
                },
                {
be79dd15   liuqimichale   道闸
343
                  value: data[1],
66faa378   liuqimichale   道闸 诱导屏
344
                  name: '道闸',
e00e4982   liuqimichale   道闸 诱导屏
345
346
347
348
349
                  itemStyle: {
                    normal: {
                      color: {
                        colorStops: [{
                          offset: 0,
66faa378   liuqimichale   道闸 诱导屏
350
                          color: '#00CAFE' // 0% 处的颜色
e00e4982   liuqimichale   道闸 诱导屏
351
352
                        }, {
                          offset: 1,
66faa378   liuqimichale   道闸 诱导屏
353
                          color: '#2772F4' // 100% 处的颜色
e00e4982   liuqimichale   道闸 诱导屏
354
355
356
357
                        }]
                      },
                    }
                  }
66faa378   liuqimichale   道闸 诱导屏
358
359
                },
  
e00e4982   liuqimichale   道闸 诱导屏
360
361
              ],
              animationType: 'scale',
974ee116   liuqimichale   道闸
362
              animationEasing: 'elasticOut'
e00e4982   liuqimichale   道闸 诱导屏
363
364
365
366
367
368
            }
  
          ]
        })
      },
      initChart() {
974ee116   liuqimichale   道闸
369
        this.chart = echarts.init(this.$el)
e00e4982   liuqimichale   道闸 诱导屏
370
371
372
373
374
        this.setOptions(this.chartData)
      }
    }
  }
  </script>