antvis/G2

Do you want to work on this issue?

You can request for a bounty in order to promote it!

在5.x版本实现类似annotation().html,点击图例实时改变环形图中间总数 #6570

houxingx posted onGitHub

问题描述

绘制环形图,中心展示总人数。4.x版本可以使用annotation().html来实现,如下G2 plot源码 chart.annotation().html({ position: ['50%', '100%'], html: (container, view) => { const coordinate = view.getCoordinate(); // 弧形的坐标 ... // todo G2 层修复可以返回空字符串 & G2 层修复允许返回非字符串的内容,比如数值 number return text ? (isString(text) ? text : ${text}) : '<div></div>'; }, });

现在需要使用G2 5.x版本实现类似功能,已经不支持。 image

参考了几种方法都不行 1、https://github.com/antvis/G2/discussions/5255

2、直接更新style mark.style("text", "100人"); chart.render(); 更新后,取消展示的图例又会刷新

3、直接增加事件 interval: click,事件ev中没有找到图例信息

4、直接配置``` legend( { click: function() { ... 在react中形成闭包,处理很麻烦 } })

```

有没有更简洁的办法实现

重现链接

No response

重现步骤

No response

预期行为

No response

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response


官网有案例代码,使用标签即可。

posted by hustcc 4 months ago

看到官网的示例了。如A、B、C,初始化总数是A+B+C;在点击图例,隐藏掉A,总数改成B+C的值。 根据这个案例:https://g2.antv.antgroup.com/zh/examples/general/pie/#donut-base 如上的方法2:点击图例时获取隐藏的图例,获取已经配置的标签实例,更新再render。 const totleTextMark = chart.getNodeByType["text"][n]; totleTextMark.style("text", "100人"); chart.render(); 但这样,隐藏置灰掉的图例A的样式会重置。 不chart.render(),不更新 text新配置的值

posted by houxingx 4 months ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests