G2 icon indicating copy to clipboard operation
G2 copied to clipboard

[Feat]: 柱状图hover到空白区域怎么不显示tooltip

Open mjhmjh666 opened this issue 3 months ago • 5 comments

Describe the feature / 功能描述

Image 如上图,堆叠柱状图hover到空白区域会出现tooltip,更希望的是hover到实体柱上再出现tooltip。

Are you willing to contribute? / 是否愿意参与贡献?

Please select / 请选择

mjhmjh666 avatar Sep 24 '25 02:09 mjhmjh666

官方图表示例地址:https://g2.antv.antgroup.com/examples/analysis/group#bar-stacked-diverging

mjhmjh666 avatar Sep 24 '25 02:09 mjhmjh666

Image 版本号为5.4.1,实测上述方法无效

mjhmjh666 avatar Sep 24 '25 02:09 mjhmjh666

需要新增参数来控制空白部分是否显示 tooltip

interstellarmt avatar Sep 24 '25 03:09 interstellarmt

@mjhmjh666 有没有兴趣提个 PR 呀,可以加个 trigger 参数控制一下,默认是 plot,可配置为 element,在 tooltip 交互里面判断一下 event.target 。

https://github.com/antvis/g2/blob/v5/src/interaction/tooltip.ts

lxfu1 avatar Sep 24 '25 03:09 lxfu1

方案:

interaction.tooltip 新增 trigger 参数,默认是 plot,可选 element、plot

代码地址:https://github.com/antvis/G2/blob/v5/src/interaction/tooltip.ts 关键代码片段:

Image

interstellarmt avatar Sep 24 '25 03:09 interstellarmt