-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathdonut.ts
88 lines (85 loc) · 1.76 KB
/
donut.ts
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
import { Chart } from '@antv/g2';
const data = [
{ item: '事例一', count: 40, percent: 0.4 },
{ item: '事例二', count: 21, percent: 0.21 },
{ item: '事例三', count: 17, percent: 0.17 },
{ item: '事例四', count: 13, percent: 0.13 },
{ item: '事例五', count: 9, percent: 0.09 },
];
const chart = new Chart({
container: 'container',
autoFit: true,
height: 500,
});
chart.data(data);
chart.scale('percent', {
formatter: (val) => {
val = val * 100 + '%';
return val;
},
});
chart.coordinate('theta', {
radius: 0.75,
innerRadius: 0.6,
});
chart.tooltip({
showTitle: false,
showMarkers: false,
itemTpl: '<li class="g2-tooltip-list-item"><span style="background-color:{color};" class="g2-tooltip-marker"></span>{name}: {value}</li>',
});
// 辅助文本
chart
.annotation()
.text({
position: ['50%', '50%'],
content: '主机',
style: {
fontSize: 14,
fill: '#8c8c8c',
textAlign: 'center',
},
offsetY: -20,
})
.text({
position: ['50%', '50%'],
content: '200',
style: {
fontSize: 20,
fill: '#8c8c8c',
textAlign: 'center',
},
offsetX: -10,
offsetY: 20,
})
.text({
position: ['50%', '50%'],
content: '台',
style: {
fontSize: 14,
fill: '#8c8c8c',
textAlign: 'center',
},
offsetY: 20,
offsetX: 20,
});
chart
.interval()
.adjust('stack')
.position('percent')
.color('item')
.label('percent', (percent) => {
return {
content: (data) => {
return `${data.item}: ${percent * 100}%`;
},
};
})
.tooltip('item*percent', (item, percent) => {
percent = percent * 100 + '%';
return {
name: item,
value: percent,
};
});
chart.interaction('element-active');
chart.render();