cawkie
Posts: 12
Joined: Wed Jun 27, 2018 10:27 am

Stacked column tooltip formatter with zero values

Trying to create a shared tooltip on stacked columns.

Everything works until there are series with zero values.
Zero values seem to be causing the wrong value to be stored in the series.chart.series array atached to the object passed to the formatter function.

example here https://jsfiddle.net/cawkie/kfj1ye50/7

Very possible I'm using the wrong property :oops:

Any help would be appreciated.

Peter
dominik.c
Posts: 2081
Joined: Fri Aug 07, 2020 7:07 am

Re: Stacked column tooltip formatter with zero values

Hello cawkie!

We appreciate you reaching out to us!

I'm not sure if I understand your issue. When I hover the second column tooltip is displayed properly with proper values(series "serious" has value 0, which is true). Could you precise where is the problem? :-)

Can't wait for your response!
Best regards.
Dominik Chudy
Highcharts Developer
cawkie
Posts: 12
Joined: Wed Jun 27, 2018 10:27 am

Re: Stacked column tooltip formatter with zero values

Thanks for your response.

I've done some further investigation and fiddling here.
Problem seems to be when there are no values (i.e. no data at all) for a given date point.

If you hover over the first column, where only "Total (previous reporting method)" and "Serious" values exist, the tooltip shows values from all the series. Displayed values for the series which do not have values are pulled from the first column where values exist for those series.
In the second column the the missing series values are pulled from the second column where values exist for those series.
There are only two columns with those series so they are correctly missing from the array on the third column.
If you hover over the last two columns they include "Total (previous reporting method)" and "Serious" with values taken from the first two date points.
There are values for "Serious" in the penultimate column. Here mousing over the "Serious" segment in the stack shows a separate tooltip with the correct value, but only for "Serious". Values from column one of "Serious" are shown in the composite tooltip shown when hovering over the other segments.

It appears the column index used for a data point on each series is based on it's position in it's own data array rather than the column in the chart as a whole, and the array passed to the formatter function is constructed using that index.

Adding a zero value to all date points 'fixes' the error, however that is not what's required as there can be no data for a date as opposed to a zero value.

Apologies if this is hard to follow. It's a rather complex situation
dominik.c
Posts: 2081
Joined: Fri Aug 07, 2020 7:07 am

Re: Stacked column tooltip formatter with zero values

Hi again!

In such complex situations, it's always good to simplify the demo as much as it's possible. Then it's easier to notice the problem, but in this case, as far as I understand, you solved your issue by adding a zero value to all date points, right?

If you have any further questions feel free to reach me any time.
Best regards!
Dominik Chudy
Highcharts Developer
cawkie
Posts: 12
Joined: Wed Jun 27, 2018 10:27 am

Re: Stacked column tooltip formatter with zero values

Adding zero values doesn't really solve my problem as I need to identify those series points where there is no value as opposed to a zero value.
The issue is that the index of each point is based on the series array not the column array.

All I'm trying to do is add a Stack Total and Date to the default tooltip. :smile:

However, I have managed to solve the problem by looping through each series to find the point with a matching x value, so all good now. :cool:

Thanks for your help
dominik.c
Posts: 2081
Joined: Fri Aug 07, 2020 7:07 am

Re: Stacked column tooltip formatter with zero values

That's great to hear and congrats on finding the solution!

In case of any further questions, feel free to contact us again.
Dominik Chudy
Highcharts Developer

Return to “Highcharts Stock”