G2 icon indicating copy to clipboard operation
G2 copied to clipboard

标注自定义shape如何使用的?

Open sLin90 opened this issue 4 years ago • 3 comments

https://g2.antv.vision/zh/docs/api/general/annotation#chartannotationshapeoption

没有找到render函数的实例,不明白该怎么使用,有文档吗?

sLin90 avatar Nov 11 '22 02:11 sLin90

https://antv-g2.gitee.io/zh/examples/component/annotation#guide-region-filter1

lxliang912 avatar Nov 23 '22 02:11 lxliang912

确实在文档上,这部分不是很全,我这里 issue 先加一个伪代码案例。

chart.annotation().shape({
  render: (container) => {
    container.addShape('text', {
      text: '这里显示一个文本'
    }),
  }
})

在 render 函数中,就可以使用最原子的 G 方法去绘制 ui。另外和 shape 类似的 api,还有一个 html,使用 html 去绘制标注,建议你可以使用后者。

hustcc avatar Dec 06 '22 03:12 hustcc

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],
  // },
});

Rui-m-i avatar Dec 13 '24 11:12 Rui-m-i