Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

highchart chart redraw method is not refreshing the chart

Tags:

highcharts

I am curious to know why button 2 is not working in this example

In this jsfiddle example 'update' method attached to button 1 is working, but in my original code 'update' is also not working. It shows error: "object# has no method 'update'"

$(function () {
    var options= {
        chart: {
            renderTo: 'container',
            height: 400
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        
        series: [{
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]        
        }]
    };
   
    var chart = new Highcharts.Chart(options);
    buttonhandle1();
    buttonhandle2()
});

function buttonhandle1(){
    $("#b1").click(function(){
            var chart = $('#container').highcharts();
            chart.yAxis[0].update({
                min:0,
            max: 5,
            tickInterval : 1,
        });
    });
}

function buttonhandle2(){
    var chart = $('#container').highcharts();
    $("#b2").click(function(){
        chart.yAxis[0].min= 0;
        chart.yAxis[0].max= 5;
        chart.yAxis[0].tickInterval = 1;
        chart.redraw();
    });
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
<button id="b1"> button 1</button>
<button id="b2"> button 2</button>
like image 982
shaaaa Avatar asked Mar 23 '23 16:03

shaaaa


1 Answers

Because when you use chart.redraw() you should also set isDirty flag as true

http://jsfiddle.net/uKWQ9/3/

chart.yAxis[0].isDirty = true;
like image 119
Sebastian Bochan Avatar answered Mar 26 '23 04:03

Sebastian Bochan