Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
houxingx opened this issue Dec 28, 2024 · 2 comments
Labels
waiting for maintainer Triage or intervention needed from a maintainer

Comments

@houxingx
Copy link

问题描述

绘制环形图,中心展示总人数。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}) : '

';
},
});

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

参考了几种方法都不行
1、#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_
@hustcc
Copy link
Member

hustcc commented Dec 29, 2024

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

@houxingx
Copy link
Author

看到官网的示例了。如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新配置的值

@interstellarmt interstellarmt added the waiting for maintainer Triage or intervention needed from a maintainer label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for maintainer Triage or intervention needed from a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants