question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding tooltip to x/y axis tick labels

See original GitHub issue

Hi 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:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
williastercommented, Nov 24, 2020

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 for TooltipInPortal 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 uses react-use-measure under the hood which requires a ResizeObserver polyfill (see @visx/tooltip docs for more)

Nov-24-2020 11-39-58

2reactions
kiranvjcommented, Nov 24, 2020

I guess this happens because you are mixing html (Tooltip component) with the SVG (text). One workaround would be to use the SVG title to show the tooltip

Example

tickComponent={ ({ formattedValue, ...tickProps }) => (
   <text {...tickProps}><title>Your tool tip here</title>{formattedValue}</text>
)}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found