Page 1 of 1

Customising tooltip

Posted: Tue Dec 04, 2018 1:30 pm
by GeorgeBT
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

Posted: Tue Dec 04, 2018 2:23 pm
by bastss
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!

Re: Customising tooltip

Posted: Tue Dec 04, 2018 2:35 pm
by GeorgeBT
Thank you! Exactly what I need your the best

Re: Customising tooltip

Posted: Tue Dec 04, 2018 4:09 pm
by GeorgeBT
Can I ask though - Is it possible to achieve the position in the stack without setting IDs?

Re: Customising tooltip

Posted: Tue Dec 04, 2018 4:31 pm
by bastss
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!

Re: Customising tooltip

Posted: Tue Dec 04, 2018 4:41 pm
by GeorgeBT
Fantastic! Thank you so much that's solved a massive headache ive been having!

Re: Customising tooltip

Posted: Tue Dec 04, 2018 4:52 pm
by bastss
You're welcome :)