Highcharts reset y axis

Firstly, I have some diagrams on my page. To make it easier to compare data in different charts, I set the maximum yAxis to the highest available.

Question How to return the maximum that I just set without reassigning the data? I am looking for something like "autoscale" since it works if I add the maximum value of 11245, the maximum value of yAxis is something like 12500. I would like to restore all my diagrams.

Demo: http://jsfiddle.net/wiesson/0p4z1mfj

$('#setMax').click(function (ev) { var yAxisMax = 0; $('[data-chart]').each(function (item) { var c = $(this).highcharts(); if (c.yAxis[0].max > yAxisMax) { yAxisMax = c.yAxis[0].max; } }); $('[data-chart]').each(function (item) { c = $(this).highcharts(); if (c.yAxis[0].max < yAxisMax) { c.yAxis[0].update({ max: yAxisMax }); } }); }); 
+5
source share
1 answer

You can simply remove the extremes from the axis. In general, I would suggest using axis.setExtremes(min, max) instead of axis.update(options) . setExtremes should have much better performance than update .

the code:

 $('#setDefault').click(function (ev) { $('[data-chart]').each(function (item) { $(this).highcharts().yAxis[0].setExtremes(null, null); }); }); 

And the demo: http://jsfiddle.net/0p4z1mfj/9/

+3
source

Source: https://habr.com/ru/post/1207390/


All Articles