javascript - Multiple Google Charts on one page - Loading Library efficiently? -
javascript - Multiple Google Charts on one page - Loading Library efficiently? -
i've seen many people inquire having multiple google charts on 1 page, , reply "your html/js wrong", or "just add together of them in 1 function that's called in setonloadcallback".
my issue bit different. if want buttons, client side, that, when clicked, generate google chart. need phone call "google.load(....)" every time, , setonloadcallback well, or there way load once, , point forwards utilize loaded objects?
the thing can think of store flag that's updated on first google.setonloadcallback, , if flag set, don't load again, if clicks few buttons have issued "load" function calls.
basically want 1 generic function can phone call (i create myself) don't want function calling google.load everytime, feels inefficient.
how go efficiently?
google.load
should indeed called 1 time per page load. don't have set charts 1 function, can create several functions , phone call them whenever want, following:
google.load('visualization', '1.1', { packages: ['corechart', 'controls'], language: 'en' }); function drawfirstvisualizations() { chart1 = new google.visualization.chartwrapper({ 'charttype': 'linechart', }); chart2 = new google.visualization.chartwrapper({ 'charttype': 'linechart', }); chart1.draw(); chart2.draw(); } function drawsecondvisualizations() { chart3 = new google.visualization.chartwrapper({ 'charttype': 'linechart', }); chart4 = new google.visualization.chartwrapper({ 'charttype': 'linechart', }); chart3.draw(); chart4.draw(); } google.setonloadcallback(drawfirstvisualizations); function functionbeingcalledlater() { google.setonloadcallback(drawsecondvisualizations); }
javascript charts google-visualization
Comments
Post a Comment