pieEchart.vue
3.47 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
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
<template>
<div class="contain">
<!-- :style="{ width: width, height: height }" -->
<div class="echart" ref="myChart" :style="{ width: width, height: height }"></div>
</div>
</template>
<script>
export default {
props: {
width: {
type: String,
// default: () => {
// return "";
// },
default: ''
},
height: {
type: String,
default: ''
},
topDataObj: {
type: Object,
default: () => {}
}
},
data() {
return {
pieData: [
{ value: 0, name: '未加企微' },
{ value: 0, name: '已加企微' }
]
}
},
mounted() {
this.$nextTick(() => {
this.pieData[0].value = this.topDataObj.entmicroNotAddCustomerCount
this.pieData[1].value = this.topDataObj.entmicroAddCustomerCount
this.initChart()
})
},
methods: {
initChart() {
// 基于准备好的dom,初始化echarts实例
let myChart = this.$echarts.init(this.$refs.myChart)
// 绘制图表
myChart.setOption({
/* title: {
text: '客户总数',
subtext: '已加和未加企微的所有潜客和已购买客户',
left: '20',
top: '20',
textStyle: {
},
subtextStyle: {
fontSize: '12px',
fontWeight: '400',
color: '#808080'
}
},*/
tooltip: {
trigger: 'item', //模板变量有 {a}、{b}、{c}、{d},分别表示系列名,数据名,数据值,百分比。{d}数据会根据value值计算百分比
formatter: '{b} : {c}人 ({d}%)'
},
color: ['#5850FF', '#FFB21F'],
// legend: {
// orient: "vertical",
// bottom: "bottom",
// },
series: [
{
name: '客户总数',
type: 'pie',
// radius: '118px',
center: ['50%', '36%'],
radius: ['32%', '48%'],
stillShowZeroSum: false,
data: this.pieData,
// data: [
// { value: 3000, name: '未加企微' },
// { value: 7000, name: '已加企微' }
// ],
// emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)',
//下面控制显示饼状图上百分比
normal: {
// color: function (params) {
// //自定义颜色
// var colorList = [
// "#00FFFF",
// "#00FF00"
// ];
// return colorList[params.dataIndex];
// },
label: {
// position: 'inner',
// formatter: '{d}%',
// show: true,
// color: '#fff'
// formatter: "{b}:\n{c}人({d}%)",
formatter: '{b}\n{d}%',
// fontWeight: "bold",
color: '#666666',
textStyle: {
fontWeight: 'normal',
fontSize: 14,
lineHeight: 21
}
// color: ["#1296db", "#d42378"],
},
labelLine: { show: true }
}
}
// },
}
]
})
}
}
}
</script>
<style lang="scss" scoped>
.contain {
position: relative;
z-index: 9;
}
</style>