Google is undefiend

21 views
Skip to first unread message

vicky84

unread,
Jul 27, 2011, 9:12:07 AM7/27/11
to Google Visualization API, vikrant.r...@gmail.com
Hi,


I am using the following code to display charts using Gooogle
Visualization API. it was working and able to see the charts on the
UI . And now i am not able to see the charts, just a blank screen and
showing a javascript error message like 'Google is Undefined'.

please can somebody help me out in this.

thanks in advance.... :)

<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<title></title>
<script type="text/javascript" src="http://www.google.com/jsapi">
function graph1(GraphType)
{
debugger;
var divid="chart_div";
var Notstarted=1;
var completed=2;
var Inprogress=3;
var sttitle="sttitle";


if(GraphType==1)
{
//google.setOnLoadCallback(drawChart);
drawChart(divid,Notstarted,completed,Inprogress,sttitle);
}
else
{
drawVisualization(divid,Notstarted,completed,Inprogress,sttitle);
}

}
function graph2(GraphType)
{
debugger;
var Notstarted=3;
var completed=2;
var Inprogress=4;
var divid2="visualization";
var sttitle="sttitle2";
if(GraphType==1)
{
drawChart(divid2,Notstarted,completed,Inprogress,sttitle);
}
else
{
drawVisualization(divid2,Notstarted,completed,Inprogress,sttitle);
}

}
function drawChart(divid, Notstarted, completed, Inprogress, sttitle)
{

var data = new google.visualization.DataTable();
data.addColumn('string', 'Task');
data.addColumn('number', 'Hours per Day');
data.addRows(5);
data.setValue(0, 0, 'Not started');
data.setValue(0, 1, Notstarted);
data.setValue(1, 0, 'In progress');
data.setValue(1, 1, Inprogress);
data.setValue(2, 0, 'Completed');
data.setValue(2, 1, completed);


var chart = new
google.visualization.PieChart(document.getElementById(divid));
chart.draw(data, { title: sttitle, legend: 'bottom' });
}
function
drawVisualization(divid2,Notstarted,completed,Inprogress,sttitle) {

var wrapper = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
dataTable: [['Not started', 'In progress',
'Completed'],
[Notstarted, Inprogress, completed]],
options: {'title': sttitle,'legend': 'bottom'},
containerId: divid2
});
wrapper.draw();
}

</script>

</head>
<body onload="graph1(1);graph2(2);" >
<table>
<tr>
<td><div id="chart_div" style="width: 300; height: 300;" >Loading
graph1...</div></td>
<td><div id="visualization" style="width: 300; height: 300;">Loading
graph2...</div></td>
</tr>
</table>


</body>
</html>

asgallant

unread,
Jul 27, 2011, 9:43:29 AM7/27/11
to google-visua...@googlegroups.com, vikrant.r...@gmail.com
I don't know if you can include your js in the same script that you call Google's jsapi from (I've never seen it done, and it didn't work when I tried it on the visualization playground).  Separate them out, load the Google visualization API, and replace the onload function in your body tag with google.setOnLoadCallback():

<script type="text/javascript" src="http://www.google.com/jsapi" />
<script>
google.load('visualization', '1', {packages: ['corechart']});
google.setOnLoadCallback(init);

function init() {
     graph1(1);
     graph2(2);
}
...rest of your code...
</script>

setOnLoadCallback takes a function as a parameter (I arbitrarily made one named init), not a function call:

// this works:
google.setOnLoadCallback(init);

// this fails:
google.setOnLoadCallback(graph1(1));

Give that a spin and see if it works.

Vikranth Papisetty

unread,
Aug 3, 2011, 5:50:03 AM8/3/11
to google-visua...@googlegroups.com
Hi,

I am using this code from our server. At first this was working properly with no errors. nowadays i am getting this error "google is undefiend". when i restart the server, i am not getting this error. After few hours again i am getting this error. could please help me why this is happening.

Thanks much.
Reply all
Reply to author
Forward
0 new messages