开发者

window.onload doesn't work with Google Chart API

I want to put google chart into开发者_如何学C window.onload, but it doesn't show anything instead, in the status bar, it shows 'Transferring data from www.google.com...' I know if we put the code outside window.onload it will surely work, but I want to put in window.onload. Any suggestions? thanks

Here is my code

window.onload doesn't work with Google Chart API


drawChart callback should be invoked when API would be loaded, for that you need to define callback key in third argument of google.load function:

(function(window, document, undefined) {
  window.onload = function() {
    google.load('visualization', '1', {
      packages:['corechart'],
      callback: drawChart
    });

    function drawChart() {
      console.log('drawChart');
    }
  };
})(window, window.document);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜