问题
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