Skip to content

Adding tooltip to x axis on XY Chart #1413

Answered by williaster
dalyemmett asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @dalyemmett 👋 thanks for checking out visx. I made a couple of tweaks to your example to get it working (updated sandbox)

  • the xychart theme sets pointer-events: 'none' by default for tickLabels so your pointer events weren't getting triggered. I turned this off with tickLabelProps, but you could also set this at the theme level and pass the custom theme to XYChart
  • after that, the tooltip was being positioned incorrectly. the demo in your link used a vanilla SVG text element, whereas you were using the @visx/text Text component. since text is a standard react element, the demo used ref directly, but the equivalent for Text is innerRef. without correctly setting containerRef, the Tool…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dalyemmett
Comment options

Answer selected by dalyemmett
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants