Chart API + Embed API (Analytics), problem solution.

Chart API + Embed API (Analytics), problem solution.

Google Chart API & Embed API (Analytics), if you use them directly, that will show window.google.load is not a function, After searching, there is a solution for me.

script(type="text/javascript", src="//www.gstatic.com/charts/loader.js")  
script(type="text/javascript")  
    google.load = google.load || google.charts.load;
    google.setOnLoadCallback = google.setOnLoadCallback || google.charts.setOnLoadCallback;

(function(w,d,s,g,js,fs){
  g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};
  js=d.createElement(s);fs=d.getElementsByTagName(s)[0];
  js.src='https://apis.google.com/js/platform.js';
  fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};
}(window,document,'script'));

// start to use API and draw chart ...

Ref

CaesarChi

Web developer, focus on website fullstack, special JavaScript, and love sharing developing experience and communicate with developers. http://about.me/clonn