Skip to content

Commit 7fb1542

Browse files
authored
docs: 增加一个饼图 demo(个性化标签饼图) (#2853)
1 parent 94adfa4 commit 7fb1542

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

examples/pie/basic/demo/meta.json

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
},
2929
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*QyXPRK-URmUAAAAAAAAAAAAAARQnAQ"
3030
},
31+
{
32+
"filename": "pie-custome-label.ts",
33+
"title": {
34+
"en": "Pie plot - custome label",
35+
"zh": "饼图-个性化标签"
36+
},
37+
"screenshot": "https://cdn.nlark.com/yuque/0/2021/png/22203542/1631705960519-bab7f151-f210-4fc4-b33c-72386996888e.png"
38+
},
3139
{
3240
"filename": "quarter-circle.ts",
3341
"title": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Pie, G2 } from '@antv/g2plot';
2+
const G = G2.getEngine('canvas');
3+
4+
const data = [
5+
{ type: '分类一', value: 100 },
6+
{ type: '分类二', value: 200 },
7+
{ type: '分类三', value: 300 },
8+
{ type: '分类四', value: 100 },
9+
{ type: '分类五', value: 100 },
10+
{ type: '其他', value: 200 },
11+
];
12+
13+
const cfg = {
14+
appendPadding: 10,
15+
data,
16+
angleField: 'value',
17+
colorField: 'type',
18+
radius: 0.75,
19+
legend: false,
20+
label: {
21+
type: 'spider',
22+
labelHeight: 40,
23+
formatter: (data, mappingData) => {
24+
const group = new G.Group({});
25+
group.addShape({
26+
type: 'circle',
27+
attrs: {
28+
x: 0,
29+
y: 0,
30+
width: 40,
31+
height: 50,
32+
r: 5,
33+
fill: mappingData.color
34+
},
35+
});
36+
group.addShape({
37+
type: 'text',
38+
attrs: {
39+
x: 10,
40+
y: 8,
41+
text: `${data.type}`,
42+
fill: mappingData.color,
43+
},
44+
});
45+
group.addShape({
46+
type: 'text',
47+
attrs: {
48+
x: 0,
49+
y: 25,
50+
text: `${data.value}${data.percent * 100}%`,
51+
fill: 'rgba(0, 0, 0, 0.65)',
52+
fontWeight: 700,
53+
},
54+
});
55+
return group;
56+
},
57+
},
58+
interactions: [{ type: 'element-selected' }, { type: 'element-active' }],
59+
}
60+
const piePlot = new Pie('container', cfg);
61+
piePlot.render();

0 commit comments

Comments
 (0)