Reputation: 1232
I've put together a simple expenses tracking page and I'm currently trying to load a Google chart using .load() - however when I load my page I receive this error:
google is not defined
function drawChart() {
https://www.google.com/jsapi is called within my chart script and works on its own but fails when loading via Ajax.
Here's what I use to call the chart..
$("#divRight").load("chart.pl?dtfm=" + dtfm + "&dtto=" + dtto);
Many thanks.
-- Code --
Snippet from chart.pl
Total: £19.15<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Description');
data.addColumn('number', 'Cost');
data.addRows([
['Groceries', 7.16],
['Web / Hosting', 5.99],
['Miscellanious', 4.00],
['Breakfast', 2.00]
]);
var options = {
title: ''
};
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id="chart_div" style='height:400px; width:400px; cursor:pointer;'></div>
Snippet from index.pl
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("#divRight").load("chart.pl?dtfm=" + dtfm + "&dtto=" + dtto);
});
</script>
Upvotes: 3
Views: 2365
Reputation: 28154
Did you include Google JSAPI script before the load and callback methods ?
Here is the code if you didn't:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
Upvotes: 1