Ready event not working as expected

纵然是瞬间 提交于 2020-01-14 14:06:37

问题


I have tried to implement the ready event handler, basically copying from the Guide however I cannot get it to work.

What am I missing?

function drawVisualization() {

    ...
    ...
    ...

    table = new google.visualization.Table(document.getElementById('table1'));
    table.draw(dataTable, {width: 1100});   

    google.visualization.events.addListener(table, 'ready', resizeTable);
}

function resizeTable() { 
    alert('Will this work?');
}

//This code does not produce an alert


回答1:


From google docs about Table events:

ready The chart is ready for external method calls. If you want to interact with the chart, and call methods after you draw it, you should set up a listener for this event before you call the draw method, and call them only after the event was fired.

So, you have to change order of code to:

...
table = new google.visualization.Table(document.getElementById('table1'));

google.visualization.events.addListener(table, 'ready', resizeTable);

table.draw(dataTable, {width: 1100});   
...


来源:https://stackoverflow.com/questions/21810488/ready-event-not-working-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!