I copy my reply to the other question, very similar to this one:
Here is a code example that is working well for me, with a dynamic loading
of the API.
For those that are not in the details:
Note that the point here is that sometimes you want to load the API after
the page was fully loaded, and so calling setOnLoadCallback() is meaningless
(since this event was already triggered by the browser).
For these cases, you can use the dynamic API loading as in the example here.
In this case you specify the callback function to be called as a parameter
to the google.load function.
VizGuy
<html>
<head>
<script type="text/javascript" src="http://www.google.com/jsapi
"></script>
<script type="text/javascript">
function init() {
google.load("visualization", "1", {packages:["areachart"], callback:
drawChart});
}
var chart;
var div;
var data;
function drawChart() {
data = new google.visualization.DataTable();
data.addColumn('string', 'Year');
data.addColumn('number', 'Sales');
data.addRows(3);
data.setValue(0, 0, '2004');
data.setValue(0, 1, 1000);
data.setValue(1, 0, '2005');
data.setValue(1, 1, 1170);
data.setValue(2, 0, '2006');
data.setValue(2, 1, 1660);
div = document.getElementById('chart_div');
div.innerHTML = '';
chart = new google.visualization.AreaChart(div);
chart.draw(data, {width: 400, height: 240});
}
</script>
</head>
<body>
<button onclick="init()">try now</button>
<div id="chart_div"></div>
</body>
</html>
On Sat, Nov 29, 2008 at 11:51 PM, jago <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> Is it possible at all to load the visualization libraries dynamically?
> Read on.
>
> I followed the tip to use
> http://code.google.com/apis/ajax/documentation/#Dynamic
>
> Using does work:
> function loadMaps() {
> google.load("maps", "2", {"callback" : draw});
> }
>
>
> What doesn't work if I try the following:
> google.load("visualization", "1", {packages:['piechart']},
> {'callback' : draw}, );
>
> It leaves the page and doesn't continue loading (Browser tells me he
> is busy).
>
> The new page shown in the browser is empty. It's DOM has the following
> content:
> <html><head>
> <meta http-equiv="content-type" content="text/html;
> charset=UTF-8"><script src="http://www.google.com/uds/?
> file=visualization&v=1&packages=piechart<http://www.google.com/uds/?file=visualization&v=1&packages=piechart>"
> type="text/
> javascript"></script></head></html>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Visualization 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-visualization-api?hl=en
-~----------~----~----~----~------~----~------~--~---