GeorgeBT
Posts: 4
Joined: Tue Dec 04, 2018 10:31 am

Customising tooltip

Good afternoon,

I’m using highcharts for a project and was wondering if anyone could help with a few small queries.

I have this example chart here: https://codepen.io/GeorgeBT/pen/pQYXyw?editors=1111 to illustrate what I would like.

I want to add a few bits of information to the tooltip on my chart.

Firstly, I would like to get the total number of chunks in the stacked bar. So in my example there’s 3 different chunks, so I would like the tooltip to say total chunks: 3
Secondly, I would like to get the chunks position in the stack. So, if the user hovers over the first chunk it will be position 1.
Thirdly, I would like to be able to get the average of the data in the tooltip - I suppose this would just be dividing the total (Which I have) by the number of chunks in the stack.

If anybody could help on these queries I would be greatly appreciated!

Many thanks,
George
bastss
Site Admin
Posts: 1192
Joined: Wed Oct 17, 2018 10:59 am

Hey George!

You're welcome - DEMO: https://jsfiddle.net/Bastss/h9rgyL6z/. I've added id for point to get his position. API: https://api.highcharts.com/highcharts/s ... ar.data.id.

Best regards!
Sebastian Wędzel,
Highcharts Developer
GeorgeBT
Posts: 4
Joined: Tue Dec 04, 2018 10:31 am

Re: Customising tooltip

Thank you! Exactly what I need your the best
GeorgeBT
Posts: 4
Joined: Tue Dec 04, 2018 10:31 am

Re: Customising tooltip

Can I ask though - Is it possible to achieve the position in the stack without setting IDs?
bastss
Site Admin
Posts: 1192
Joined: Wed Oct 17, 2018 10:59 am

Re: Customising tooltip

Yes, it is possible - this will be series.index but we have to add 1 because counting starts from 0. Check example: https://jsfiddle.net/Bastss/4pjsky8q/.

Kind regards!
Sebastian Wędzel,
Highcharts Developer
GeorgeBT
Posts: 4
Joined: Tue Dec 04, 2018 10:31 am

Re: Customising tooltip

Fantastic! Thank you so much that's solved a massive headache ive been having!
bastss
Site Admin
Posts: 1192
Joined: Wed Oct 17, 2018 10:59 am

Re: Customising tooltip

You're welcome :)
Sebastian Wędzel,
Highcharts Developer

Return to “Highcharts Usage”