Skip to content

Commit b9ba033

Browse files
committed
docs: 增加图例自定义 marker 的demo
close: #2953
1 parent ce2a4ea commit b9ba033

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

docs/common/marker.en.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66

77
_Marker_ The supported tag types are: _circle | square | line | diamond | triangle | triangle-down | hexagon | bowtie | cross | tick | plus | hyphen_
88
_MarkerCallback_ is `(x: number, y: number, r: number) => PathCommand`
9+
10+
[DEMO](zh/examples/component/legend#legend-marker-customize) of `Customize legend marker`.

docs/common/marker.zh.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414

1515
回调的方式为:`(x: number, y: number, r: number) => PathCommand`
1616

17+
自定义图例 marker [DEMO](zh/examples/component/legend#legend-marker-customize)
18+
1719
<!--这里可以插入一个代码示例-->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Column } from '@antv/g2plot';
2+
3+
fetch('https://gw.alipayobjects.com/os/antfincdn/P14mCvkybz/large-datra.json')
4+
.then((data) => data.json())
5+
.then((data) => {
6+
const plot = new Column('container', {
7+
data,
8+
xField: 'product_box',
9+
yField: 'value',
10+
seriesField: 'province',
11+
isGroup: 'true',
12+
legend: {
13+
flipPage: true,
14+
maxRow: 2,
15+
marker: {
16+
// 把 marker 从 square 变成线条
17+
symbol: (x, y, r) => {
18+
return [
19+
['M', x - r / 2, y],
20+
['L', x + r / 2, y],
21+
];
22+
},
23+
style: (oldStyle) => {
24+
return {
25+
...oldStyle,
26+
r: 4,
27+
lineWidth: 2,
28+
// square marker 只有填充色,赋给 line 的 stroke
29+
stroke: oldStyle.stroke || oldStyle.fill,
30+
};
31+
},
32+
},
33+
},
34+
});
35+
36+
plot.render();
37+
});

examples/component/legend/demo/meta.json

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
"en": "Legend flip-page configuration"
4444
},
4545
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/W6n7yMd5lw/0a28a2bd-e5f3-4756-8fda-d8e2faf79076.png"
46+
},
47+
{
48+
"filename": "legend-marker-customize.ts",
49+
"title": {
50+
"zh": "图例 marker 自定义",
51+
"en": "Customize legend marker"
52+
},
53+
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/w87M340IdH/5f2f2e58-8426-4f6e-8100-7529ed57b5ed.png"
4654
}
4755
]
4856
}

0 commit comments

Comments
 (0)