Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ready event not working as expected

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

like image 899
php-b-grader Avatar asked Oct 21 '25 13:10

php-b-grader


1 Answers

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});   
...
like image 149
Anto Jurković Avatar answered Oct 23 '25 03:10

Anto Jurković