Highcharts's onReady event?

后端 未结 3 1209
一个人的身影
一个人的身影 2021-02-19 03:34

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

Currently, HighCharts only offers addSeries, click, load

3条回答
  •  天命终不由人
    2021-02-19 04:25

    This is definitely less elegant than the accepted answer, but still works fine with a few lines of code. The essence is to simply poll all chart container HTML elements.

    The code below assumes you have one or more Highcharts attached to elements having class="chart":

    var chartsToLoad = [];
    
    $('.chart').each(function(n,elem) {
    
        chartsToLoad[n] = window.setInterval(function() {
    
            if(typeof($(elem).highcharts()) !== 'undefined') {
    
                // It's loaded now, go ahead...
                $(elem).highcharts().doSomeHighchartsStuffHere()
    
                // Permanently stop polling
                window.clearInterval(chartsToLoad[n]);
            }
    
      }, 100); // Check every 100ms
    
    
    });
    

提交回复
热议问题