Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts's onReady event?

Is there any onReady (or similar) ready event for HighCharts?

Currently, HighCharts only offers addSeries, click, load, redraw, and selection for chart object (http://www.highcharts.com/ref/#chart-events). Apparently the load should be the one which fires "on chart ready" event, but it's not. It's firing the event "when data is loaded"

Here is a sample they have for load: http://jsfiddle.net/hgbQm/

Here is a modified version of the above code which shows the chart is not ready when load is fired: http://jsfiddle.net/QzKky/1/

Any idea?

Alternatively, I will need to do a delayed calls but that will be so ugly. Thanks!

like image 262
Lionel Chan Avatar asked Aug 08 '11 08:08

Lionel Chan


1 Answers

Indeed the delayed call is not a very good approach. The load event is working properly, but the current chart is referred by the this keyword, i.e.

// create the chart
var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container',
        events: {
            load: function(event) {
                //When is chart ready?
                console.log(this); //this refers to the loaded chart.
            }
        }        
    },
    xAxis: {
    },

    series: [{
        animation: false,
        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]     
    }]
});

Demo

Hope this helps :)

like image 137
stecb Avatar answered Sep 20 '22 13:09

stecb