PieChart.vue
1.99 KB
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
<template>
<div>
<p class="line-color-title">{{title}}</p>
<div ref="pieChart" style="margin-top:10px;width: 100%; height: 20vh;"></div>
</div>
</template>
<script>
import * as echarts from 'echarts';
import resize from './../mixin/resize'
export default {
name: 'PieChart',
mixins:[resize],
props: {
title:{
type: String,
default: '',
},
data: {
type: Array,
default: () => [],
},
colors: {
type: Array,
default: () => ['#50CEFB', '#5850FF','#FBBE50','#90D55C','#FDDB93','#A1EDFF','#6EA3FF','#FF5A92','#BCCAFF','#9F6EFF'],
},
},
mounted() {
this.initChart(this.$refs.pieChart);
this.drawChart();
},
methods: {
drawChart() {
const chart = echarts.init(this.$refs.pieChart);
const option = {
// tooltip: {
// trigger: 'item',
// },
legend: {
show: false,
},
series: [
{
type: 'pie',
radius: ['40%', '60%'],
avoidLabelOverlap: false,
label: {
show: true,
position: 'outside',
formatter: function(params) {
return '{a|' + params.value + '%'+ '}'
+'\n'+'\n'+
' {b|' + params.name + '}'
},
rich: {
a: {
color: '#50CEFB',
fontWeight: 'bold',
fontSize:'18px'
},
b: {
color: '#333',
fontSize:'14px',
}
}
},
labelLine: {
show: true
},
data: this.data,
itemStyle: {
color: (params) => {
return this.colors[params.dataIndex];
},
},
},
],
};
chart.setOption(option);
},
},
};
</script>
<style lang="scss">
/* 您可以根据需要添加自定义样式 */
</style>