Recharts CustomTooltip 失去背景不透明度
我第一次遇到这个问题是在实现我自己的 CustomTooltip 时,但我认为这实际上可能是一个 recharts 错误,因为即使 codesandbox 示例 也存在同样的问题。如果删除 'content={< CustomTooltip />}' 从该codesandbox上的第110行开始,您将把工具提示变成基本工具提示,如下所示:
但是当你把那块放回去时这就是文档中作为 CustomTooltip 示例的内容,工具提示的背景(由于缺乏更好的术语)消失了。
有谁知道这是否是重新图表错误,或者也许我只是做错了什么?我只是想让我的自定义工具提示具有与基本工具提示相同的视觉外观
I first came across this when implementing my own CustomTooltip, but I think this might actually be a recharts bug, as even the codesandbox example from the documentation site has the same issue. If you remove 'content={< CustomTooltip />}' from line 110 on that codesandbox, you'll turn the tooltip into a basic one, which will look like this:
But when you put that piece back in so that it's what the documentation has as an example for a CustomTooltip, the background (for lack of a better term) of the tooltip disappears.
Does anyone know if this is a recharts bug, or maybe I'm just doing something wrong? I just want to get my Custom Tooltip to have the same visual look as the basic one
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想通了。正如 rahuuzz 所说,为工具提示提供自定义内容也会覆盖基本样式,因此必须提供。我的图表中的工具提示现在看起来像这样:
基本上只需添加带有一些基本样式的wrappedStyle 道具。希望这可以帮助其他人将来进行谷歌搜索
I figured it out. As rahuuzz said, providing custom content for the tooltip also overrides the base styling, so that has to be provided. My tooltip in my chart now looks like this:
Basically just had to add the wrappedStyle prop with some basic styling. Hopefully this helps someone else googling in the future
在您的codesandbox中,您正在导入
styles.css
,但它不包含custom-tooltip类的任何样式。当您为工具提示提供自定义内容时,您必须自己定义样式。当省略
content
属性时,包会在内部将样式设置为工具提示。In your codesandbox you are importing
styles.css
but It doesnt contain any styles for custom-tooltip class.When you provide custom content for the tooltip you have to define the styles yourself. When
content
prop is omitted, the package sets the style internally to the tooltip.