If you are drawing the charts as a part of a Dashboard, this is fairly straightforward: you need to initialize your accordian function in a 'ready' event handler for the dashboard, like this:
var dash = new google.visualization.Dashboard(document.getElementById('chart_div'));
google.visualization.events.addListener(dash, 'ready', function () {
// initialize accordian function here
});
If you are drawing them separately, then this becomes slightly more complicated, as you have to wait for all of the charts to finish drawing. Something like this should work:
var charts = {
chart1: {
chart: new google.visualization.ChartWrapper({/*wrapper setup*/}),
ready: false
},
chart2: {
chart: new google.visualization.ChartWrapper({/*wrapper setup*/}),
ready: false
}
// ...
};
for (i in charts) {
google.visualization.events.addListener(charts[i].chart, 'ready', (function (x) {
charts[x].ready = true;
var allReady = true;
for (j in charts) {
allReady = (allReady && charts[j].ready);
if (allReady == false) {
break;
}
}
if (allReady) {
// initialize accordian function here
}
})(i));
}
That will handle an arbitrary number of charts; if you only have two, then you can simplify it:
var chart1 = new google.visualization.ChartWrapper({/*wrapper setup*/});
var chart2 = new google.visualization.ChartWrapper({/*wrapper setup*/});
var otherDone = false;
google.visualization.events.addListener(chart1, 'ready', function (x) {
if (otherDone) {
// initialize accordian function here
}
else {
otherDone = true;
}
});
google.visualization.events.addListener(chart2, 'ready', function (x) {
if (otherDone) {
// initialize accordian function here
}
else {
otherDone = true;
}
});