Javascript Google可视化仪表板:getChart()空对象

Javascript Google可视化仪表板:getChart()空对象,javascript,jquery,html,google-visualization,Javascript,Jquery,Html,Google Visualization,在GoogleVisualization中,我实现了一个仪表板,带有一个表和一些控件过滤器 在html中,我添加了一个按钮,当我单击该按钮时,我希望获取所有选定的行:问题是函数getChart()返回空对象:为什么 我必须在哪里实现onclick函数 google.load('visualization', '1.0', {'packages':['controls', "corechart"]}); google.setOnLoadCallback(drawDashboard); funct

在GoogleVisualization中,我实现了一个仪表板,带有一个表和一些控件过滤器

在html中,我添加了一个按钮,当我单击该按钮时,我希望获取所有选定的行:问题是函数getChart()返回空对象:为什么

我必须在哪里实现onclick函数

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 a 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();
                    ...

    };

}

getChart
方法将返回
null
,直到ChartWrapper包装的可视化完成绘图。尝试将事件处理程序代码包装到一次性“就绪”事件侦听器中:

google.visualization.events.addOneTimeListener(table, 'ready', function () {
    document.getElementById("btn_solicit").onclick = function() {
        var tmpData = table.getChart();
        // ...
    };
});
将其放置在创建
表之后,但在调用
仪表板之前。绘制