pie.vue
3.48 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
<template>
<div class="pie-container flex">
<canvas class="canvas" :id="refId"></canvas>
<div class="list-info">
<template v-for="(legend, index) in chartData">
<div class="list-info-item" :key="index">
<div class="font-12 color-2f line-18 flex">
<div class="circle" :style="{ background: color[index] }"></div>
{{ legend.text }}
</div>
<div class="font-16 color-3 line-24 bold m-l-14">{{ legend.value }}</div>
</div>
</template>
<!-- <div class="list-info-item">
<div class="font-12 color-2f line-18 flex">
<div class="circle"></div>
已跟进 (人)
</div>
<div class="font-16 color-3 line-24 bold m-l-14">396</div>
</div> -->
</div>
</div>
</template>
<script>
import F2 from '@antv/f2/lib/index-all'
export default {
name: 'pieChart',
data() {
return {
chart: null,
chartColor: this.color,
refId: this.id,
chartData: this.list
}
},
props: {
color: {
type: Array,
default: () => []
},
list: {
type: Array,
default: () => []
},
id: {
type: String,
default: ''
},
centerData: {
type: Object,
default: () => {}
}
},
watch: {
list() {
this.initCanvas()
}
},
mounted() {
console.log(this.list)
this.initCanvas()
},
methods: {
initCanvas() {
let id = this.refId
let { chartData, chartColor, centerData } = this
this.chart && this.chart.clear()
this.chart = null
this.chart = new F2.Chart({
id,
pixelRatio: window.devicePixelRatio,
padding: [20, 20, 20, 20]
})
this.chart.source(chartData)
this.chart.coord('polar', {
transposed: true,
radius: 0.9,
innerRadius: 0.74
})
this.chart.axis(false)
this.chart.legend(false)
this.chart.tooltip(false)
this.chart.guide().html({
position: ['50%', '53%'],
html: `<div style="width: 250px;height: 40px;text-align: center;">
<div style="font-size: 12px;color: rgba(47, 64, 86, 0.7);">${centerData.text}</div>
<div style="font-size: 18px;color: #343434;margin: 0;font-weight: bold;line-height: 24px;">${centerData.rate}</div>
</div>`
// html: '<div style="text-align: center;width:150px;height: 50px;">\n <p style="font-size: 10px;color: #999;margin: 0" id="title"></p>\n <p style="font-size: 18px;color: #343434;margin: 0;font-weight: bold;" id="value"></p>\n </div>'
})
this.chart.interval().position('const*value').adjust('stack').color('text', chartColor)
// this.chart.pieLabel({
// activeShape: false,
// lineStyle: {
// stroke: '#fff' // 线的颜色
// },
// anchorStyle: {
// fill: '#fff'
// },
// onClick(ev) {
// const data = ev.data
// if (data) {
// document.getElementById('title').innerText = data.text
// document.getElementById('value').innerText = data.value
// }
// }
// })
this.chart.render()
}
}
}
</script>
<style lang="scss" scoped>
.canvas {
width: calc(100% - 135px);
height: 160px;
}
.list-info-item {
margin-top: 16px;
.circle {
width: 8px;
height: 8px;
background: #3975c6;
border-radius: 2px;
margin-right: 6px;
}
}
.list-info-item:nth-child(1) {
margin-top: 0;
}
</style>