开发者

window.onload doesn't work with Google Chart API

开发者 https://www.devze.com 2023-03-17 07:31 出处:网络
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 o

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

精彩评论

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