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
<template>
<div id="pieChart_id" style="width: 100%;height: 280px;">
</div>
</template>
<script>
export default {
name: "pieChart",
components: {
},
data () {
return {
chartData: []
}
},
props: {
title: {
type: String,
default () {
return ''
}
},
subtitle: {
type: String,
default () {
return ''
}
},
value: {
type: Array,
default () {
return []
}
},
},
created () {
this.chartData = this.value
},
mounted () {
this.$nextTick(() => {
var timer = setTimeout(() => {
this.drawChart();
clearInterval(timer);
}, 0)
})
},
methods: {
drawChart () {
let myChart = this.$echarts.init(document.getElementById("pieChart_id"))
window.addEventListener('resize', () => {
myChart.resize()
})
let option = {
title: {
text: this.title,
subtext: this.subtitle,
left: 'center'
},
tooltip: {
trigger: 'item'
},
legend: {
orient: 'vertical',
left: 'left'
},
series: [
{
name: '数据来自',
type: 'pie',
radius: '60%',
data: this.chartData,
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
}
myChart.setOption(option);
},
},
beforeDestroy () {
window.removeEventListener("resize", () => {
this.myChart.resize();
});
},
watch: {
value: {
handler (value) {
this.chartData = value
this.drawChart()
},
},
}
}
</script>
<style lang="less" scoped>
</style>