-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
labelline.ts
49 lines (40 loc) · 966 Bytes
/
labelline.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
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.coordinate('theta', {
radius: 0.75,
});
chart.data(data);
chart.scale('percent', {
formatter: (val) => {
val = val * 100 + '%';
return val;
},
});
chart.tooltip({
showTitle: false,
showMarkers: false,
});
chart
.interval()
.position('percent')
.color('item')
.label('percent', {
layout: [{ type: 'limit-in-plot', cfg: { action: 'ellipsis'/** 或 translate */ } }],
content: (data) => {
return `${data.item}: ${data.percent * 100}%`;
},
})
.adjust('stack');
chart.interaction('element-active');
chart.render();