Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts reset y Axis

First, I have several charts on my page - To make it more easy to compare data within the different charts, I'm setting the maximum yAxis to the highest one that is available.

Question: How do I revert the maximum I've just set without refetching the data? I'm looking for something like "autoscale" as it works if I add a maximum value of 11245, the maximum yAxis is something like 12500. I would like to restore all my charts.

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
            });
        }
    });
});
like image 923
wiesson Avatar asked Sep 29 '22 09:09

wiesson


1 Answers

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

Code:

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

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

like image 172
Paweł Fus Avatar answered Oct 03 '22 00:10

Paweł Fus