tomheaps
Posts: 11
Joined: Tue Mar 06, 2018 6:37 am

Show average plotline after hiding series

I am using the points from my base series[0] to calculate an average value that is displayed as a plotline on the y axis - see https://jsfiddle.net/3guh7d8m/5/.

The issue with this code is that when you hide the series, either by using a button linked to chart.series[0].hide() or by clicking on the legend item to hide the series, the plotline will disappear and the following error is thrown in the console: Uncaught TypeError: Cannot read property 'length' of null"

I understand that this occurs because after hiding the series, the points on the axis (referred to in the calculation of average) no longer exist.

You will see in my fiddle that I have set the navigator series to the same data as my base series so I wondered if there was any way of getting the points for the average calculation from the navigator rather than from the main plot as the navigator data remains visible at all times?

Any help would be much appreciated.
User avatar
sebastian.h
Posts: 1734
Joined: Fri Aug 07, 2020 7:08 am

Re: Show average plotline after hiding series

Hi,
We appreciate you reaching out to us.

I have modified your demo and added an if statement that checks if the point exists.

Live demo:
https://jsfiddle.net/BlackLabel/1587uj02/

Yes, it will be possible to get some information from the data in the navigator.

Let me know if this solution suits you.
Best regards.
Sebastian Hajdus
Highcharts Developer
tomheaps
Posts: 11
Joined: Tue Mar 06, 2018 6:37 am

Re: Show average plotline after hiding series

This solution works great.

Sorry for delay in replying!
User avatar
sebastian.h
Posts: 1734
Joined: Fri Aug 07, 2020 7:08 am

Re: Show average plotline after hiding series

Hi,
I am glad that I could help you and the proposed solution works :)

Best regards.
Sebastian Hajdus
Highcharts Developer

Return to “Highcharts Stock”