G2
G2 copied to clipboard
标注自定义shape如何使用的?
https://g2.antv.vision/zh/docs/api/general/annotation#chartannotationshapeoption
没有找到render函数的实例,不明白该怎么使用,有文档吗?
https://antv-g2.gitee.io/zh/examples/component/annotation#guide-region-filter1
确实在文档上,这部分不是很全,我这里 issue 先加一个伪代码案例。
chart.annotation().shape({
render: (container) => {
container.addShape('text', {
text: '这里显示一个文本'
}),
}
})
在 render 函数中,就可以使用最原子的 G 方法去绘制 ui。另外和 shape 类似的 api,还有一个 html,使用 html 去绘制标注,建议你可以使用后者。
chart.annotation().shape({
render: (container) => {
// 这里定义自定义形状绘制
const path = container.addShape('path', {
attrs: {
path: [
['M', 100, 250], // 箭头顶部坐标
['L', 95, 260], // 箭头底部左侧
['L', 100, 258],
['L', 105, 260], // 箭头底部右侧
['Z'], // 闭合路径
],
fill: '#293441', // 填充颜色
},
});
return path;
},
// helpers: {
// parsePosition: ['2024-12-06', 0],
// },
});