dudedolf
Posts: 8
Joined: Tue Jan 24, 2023 9:49 am

Bar Chart track when Tooltip is show

Hi,

I would like to track when the tooltip is shown and hidden (on hover of a bar). The reason is that we would like to track these 'events' for our analytics department.

I have currently tried to implement 'mouseOver' and 'mouseOut' events with varying success:
- plotOptions.bar.events - whilst i could get the series index, i could not get the 'row' index
- plotOptions.bar.point.events - did not fire mouseOver or mouseOut
- plotOptions.bar.series[x].point.events - whilst i could get the series index and the 'row' index, it breaks the display of the tooltip with the error 'Uncaught TypeError: Cannot read properties of null (reading 'tooltipOptions')'. I did try to return 'false' from these events but it did not make any different.

Could you advise of a way to achieve this.
Thank you
jakub.s
Posts: 1228
Joined: Fri Dec 16, 2022 11:45 am

Re: Bar Chart track when Tooltip is show

Hi,

Welcome to our forum and thanks for the question.

It would be very helpful if you could send me a demo of your problem, then it would be easier for me to solve it.

Here's how I see it: https://jsfiddle.net/BlackLabel/ctk572Lo/

1. plotOptions.bar.events.mouseOver will not give you a point, because it's an event on the whole series, not on a point; use plotOptions.bar.point.events.mouseOver to get information about a point you hover over.

2. plotOptions.bar.point.events.mouseOver should fire normally; if you provide me with the demo I'll try to solve it:)

3. I don't see how exactly did you use plotOptions.bar.series[x].point.events - plotOptions.bar apply to all bar series, not just one - that's the point of plotOptions. If you want to have a different behavior for a certain series, you can do it directly in the series with series.point.events.mouseOver (not in the plotOptions).

API:
https://api.highcharts.com/highcharts/s ... .mouseOver

Let me know if that helps.

Best regards,
Jakub
Jakub
Highcharts Developer
dudedolf
Posts: 8
Joined: Tue Jan 24, 2023 9:49 am

Re: Bar Chart track when Tooltip is show

Thank you for the response. In the end plotOptions.bar.series[x].point.events did work and i was able to get the data i need 'event.target.index'. The error was due to the component refresh when i updated the state in react, so used 'useRef' instead.

Thanks
Rudy
jakub.s
Posts: 1228
Joined: Fri Dec 16, 2022 11:45 am

Re: Bar Chart track when Tooltip is show

I'm glad you figured it out.

Do not hesitate to let me know if you have any more questions.

Regards,
Jakub
Jakub
Highcharts Developer

Return to “Highcharts Usage”