jahnvi25
Posts: 284
Joined: Thu Oct 04, 2012 12:16 pm

highstock compare back to null

what is the best way to set the axis.setCompare ? basically we are trying to draw seasonality chart. and when user clicks on that chart type..

we set chart.yAxis[0].setCompare('percent');
everything is working fine at this point.. and chart shows in percent mode..
but then user clicks on 'reset' to go back to original mode.. thats when i do

chart.yAxis[0].setCompare(null) --> but this is giving me below exception

highstock.src.js:50663 Uncaught TypeError: Cannot read properties of undefined (reading 'forEach')
at LineSeries.seriesSetCompare [as setCompare] (highstock.src.js:50663:33)
at highstock.src.js:50541:36
at Array.forEach (<anonymous>)
at Axis.setModifier (highstock.src.js:50538:33)
at Axis.axisSetCompare [as setCompare] (highstock.src.js:50724:22)

and if i use
chart.get('series').update({compare:null});
this does not give me any exception.. but then y-Axis range starts from zero and max from original.. it seems that its setting dataMIn to be 0..

is there a way to fix this situation..
i have complicated code and couple of series for sure.. so it would be really hard to re-create this on simple demo...
but i am just looking for some pointer just to reset the dataMin or somehow to avoid that exception..
jakub.s
Posts: 1228
Joined: Fri Dec 16, 2022 11:45 am

Re: highstock compare back to null

Hi,

Thanks for the question!

Please take a look at this demo: http://jsfiddle.net/BlackLabel/axg86b74/

I believe that yAxis.setCompare(null) should work fine. What types of series do you have linked to the yAxis you use for setCompare?

I'll try to reproduce this error and see what might be the reason for it.

Best regards,
Jakub
Jakub
Highcharts Developer
jahnvi25
Posts: 284
Joined: Thu Oct 04, 2012 12:16 pm

Re: highstock compare back to null

Thanks for reply. i did end up using series.setCompare approach.. and its working fine. i do have some hidden series without any data.. and when i do chart.yAxis[0].setCompare(null).. i am getting above exception at below code..

Code: Select all

this.points.forEach(function (point) {
                        delete point.change;
                    });
in function seriesSetCompare(compare, redraw) {} since my series does not have any points... so may be check for empty makes sense..

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

Re: highstock compare back to null

Yes, you're right.

I'm glad you figured it out.

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

Best regards,
Jakub
Jakub
Highcharts Developer

Return to “Highcharts Usage”