javascript - Google Visualization Dashboard: getChart() null object -


in google visualization have implemented dashboard, 1 table , controls filters.

in html have added button , when click on want selected rows: problem function getchart() return null object: why?

where must implement onclick function?

google.load('visualization', '1.0', {'packages':['controls', "corechart"]}); google.setonloadcallback(drawdashboard);  function drawdashboard() {      var data = new google.visualization.datatable();     data.addcolumn('string', 'name');     data.addcolumn('string', 'status');      data.addrows([       ['customer1', 'active'],       ['customer2', 'blocked'],     ]);      var dashboard = new google.visualization.dashboard(document.getelementbyid('dashboard_div'));      var stringnamefilter = new google.visualization.controlwrapper({         'controltype': 'stringfilter',         'containerid': 'filtername_div',         'options': {           'filtercolumnindex': 0,           'ui': {             'label': '',             }         }      });      // define table     var table = new google.visualization.chartwrapper({       'charttype': 'table',       'containerid': 'table_div',       'options': {           'allowhtml': true,       }      });      dashboard.bind(stringnamefilter, table);     dashboard.draw(data);      document.getelementbyid("btn_solicit").onclick = function() {         var tmpdata = table.getchart();                     ...      };  } 

the getchart method return null until visualization wrapped chartwrapper finishes drawing. try wrapping event handler code in one-time "ready" event listener:

google.visualization.events.addonetimelistener(table, 'ready', function () {     document.getelementbyid("btn_solicit").onclick = function() {         var tmpdata = table.getchart();         // ...     }; }); 

place after creating table before calling dashboard.draw.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -