On 24 Sep 2010, at 10:43, lc wrote:
> switch(chart_type) {
> case "bar":
> google.load("visualization", "1", {packages:
> ['corechart']});
> google.setOnLoadCallback(draw_bar_chart);
> break;
> // etc........
>
> default:
> alert("Unknown chart");
> return;
> }
This will still only result in a graph being drawn once. Why are you loading
the visualization library every time? Stick that google.load statement outside
the function, then call draw_bar_chart whenever you want it to happen. Calling
google.setOnLoadCallback(draw_bar_chart) repeatedly will do nothing. Something
like this:
google.load("visualization", "1", {packages:['corechart']});
google.setOnLoadCallback(draw_bar_chart);
/* chart_type: ("bar", "pie", etc.....)
* canvas: html tag (got by document.getElementBy())
* data: Array of data points
* xaxis: name of xaxis
* yaxis: name of yaxis
*/
function create_chart(chart_type,canvas,data,xaxis,yaxis) {
switch(chart_type) {
case "bar":
draw_bar_chart();
break;
// etc........
default:
alert("Unknown chart");
return;
}
...
This would set up the library, set a graph to draw once the page has loaded,
then leave you free to call create_chart any time you like to draw other charts.
I think you'll also need to pass the chart data into the draw_bar_chart
function.
Marcus
--
You received this message because you are subscribed to the Google Groups
"Google Chart API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-chart-api?hl=en.