pieChart.vue
1.83 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
<template>
<div class="chart-box">
<div id="pie" class="chart-pie"></div>
</div>
</template>
<script>
import * as echarts from 'echarts'
const DISCOUNT_TYPE = {
1: '满减券',
2: '折扣券',
3: '代金券',
4: '兑换券',
5: '购车代金券',
6: '商品折扣券',
7: '会员服务'
}
export default {
name: 'PieChart',
props: ['list'],
data() {
return {
DISCOUNT_TYPE,
option: {
tooltip: {
trigger: 'item',
formatter: '{b}\n \n{c} 张'
},
series: [
{
name: '券类营销',
type: 'pie',
radius: '60%',
label: {
formatter: '{b}\n \n{c} 张'
},
itemStyle: {
normal: {
color: function(params) {
var colorList = ['#5850FF', '#FE9C1C', '#FDB757', '#6495FA']
return colorList[params.dataIndex]
}
}
},
data: [],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
},
myChart: {}
}
},
watch: {
list(val) {
const arr = this.list.map(item => {
return {
name: this.DISCOUNT_TYPE[item.discountType],
value: item.totalIssue
}
})
this.option.series[0].data = arr
this.option && this.myChart.setOption(this.option)
}
},
methods: {},
mounted() {
let chartDom = document.getElementById('pie')
this.myChart = echarts.init(chartDom)
this.option && this.myChart.setOption(this.option)
}
}
</script>
<style lang="scss" scoped>
.chart-box {
width: 100%;
height: 185px;
}
.chart-pie {
height: 185px;
}
</style>