Adding tooltip to x/y axis tick labels
See original GitHub issueHi Guys,
I’m trying to add a Tooltip (MaterialUI) on <AxisLeft/>
currently using tickComponent. Reason is that I’m getting lengthy characters in y axis and I need to trim it and show. But when the user hovers the axis label, we need to show the entire text.
Doesn’t work -
tickComponent={ ({ formattedValue, ...tickProps }) => (
<Tooltip title="Test" arrow><text {...tickProps}>{formattedValue}</text></Tooltip>
)}
But if I remove the Tooltip wrapper, it will work.
Works-
tickComponent={ ({ formattedValue, ...tickProps }) => (
<text {...tickProps}>{formattedValue}</text>
)}
Also, if I don’t use <text/>
component and the {...tickProps}
, then I have to manually code and position all the axis labels, I guess.
So is there any way to achieve this
Any thought on this ?
Thanks, Abi
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
ASP.NET Chart: ToolTips on X and Y axis labels?
Yes you can,. to show tooltip on X-Axis Chart1.Series["SeriesName"].LabelToolTip = "#VALX [#VALY]";. and on the Y-Axis Chart1.Series["SeriesName"].
Read more >Axis Tooltips – amCharts 4 Documentation
The only way to enable axis tooltips is to enable chart cursor. Creating a chart cursor is super easy. You just instantiate an...
Read more >How to position labels between ticks and how to display a grid ...
Hi All, I'm using a RadChart. Would like to position labels between ticks as shown on Y axis in the second chart displayed...
Read more >Add Tooltip to axis label - MSDN - Microsoft
In SSRS2008 R2, we could give a tooltip to data series or give a tooltip for the report item to specify the textual...
Read more >Visualization: Column Chart - Google Developers
Like all Google charts, column charts display tooltips when the user hovers ... Charts have several kinds of labels, such as tick labels,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s a working demo. Likely can still optimize the size of the tick mouse target and the tooltip positioning / styles (should be able to use material styles inside the Portal if you need) but illustrates the general approach.
Just to explain the
containerRef
: in order forTooltipInPortal
to position itself correctly, it needs to be able to figure out the needed page-level x/y offset, relative to the parent it will be rendered in. It usesreact-use-measure
under the hood which requires aResizeObserver
polyfill (see@visx/tooltip
docs for more)I guess this happens because you are mixing html (Tooltip component) with the SVG (
text
). One workaround would be to use the SVGtitle
to show the tooltipExample