Getting error while passing php array to google graph

BHSRunningStud

New Member
Hi I am trying to pass the php array to Google graph with json_encode.When i run the script i get an error like ("Uncaught Error: Invalid type: int. format+en,default, annotated timeline +en_US.I.js:53)in Google Chrome debugger. Below is the code that I am using for drawing graph .JavaScript is new for me so please bear with me ..\[code\]<?php //$rows[]=array($yP1data,$yP2data,$yP3data,$yP4data,$xdata); $yP1data = http://stackoverflow.com/questions/10274797/array(); $yP2data = array(); $yP3data = array(); $yP4data = array(); $xdata = array(); $Timedata = array(); $Result=mysql_query("Select P1,P2,P3,P4,RecordTime from readings"); //$countt=mysql_num_rows($Result); $count=0; while($data= http://stackoverflow.com/questions/10274797/mysql_fetch_array($Result)) { array_push($yP1data,$data["P1"]); array_push($yP2data,$data["P2"]); array_push($yP3data,$data["P3"]); array_push($yP4data,$data["P4"]); array_push($Timedata,$data["RecordTime"]); //echo "<p>"; $time= (explode(" ",$Timedata[$count])); array_push($xdata,$time[1]); //print_r($xdata); $count++; }?><script type="text/javascript"> var encoded_P1data = http://stackoverflow.com/questions/10274797/<?php echo json_encode($yP1data) ?>; var encoded_P2data = <?php echo json_encode($yP2data) ?>; var encoded_P3data = <?php echo json_encode($yP3data) ?>; var encoded_P4data = <?php echo json_encode($yP4data) ?>; var encoded_xdata = <?php echo json_encode($xdata) ?>;</script><script type="text/javascript" src="http://stackoverflow.com/questions/10274797/jsapi.js"></script> <script type="text/javascript">google.load('visualization', '1', {'packages':['annotatedtimeline']});google.setOnLoadCallback(drawChart);var P1data = http://stackoverflow.com/questions/10274797/new Array; // This would be the first array passed from PHPvar P2data = new Array; // This would be the second array passed from PHPvar P3data= new Array; // This would be the third array passed from PHPvar P4data = new Array; // This would be the second array passed from PHPvar P5data= new Array;P1data = encoded_P1data; P2data = encoded_P2data; P3data= encoded_P3data; P4data = encoded_P4data; RecordTime= encoded_xdata ;\[/code\]function drawChart() { var data = http://stackoverflow.com/questions/10274797/new google.visualization.DataTable();\[code\]data.addColumn('datetime', 'RecordTime');data.addColumn('int', 'P1');data.addColumn('int', 'P2');data.addColumn('int', 'P3');data.addColumn('int', 'P4');/* create for loops to add as many columns as necessary */var len = jsonarray.length;data.addRows(len);for(i=0; i<len; i++) {data.setValue(i, 0, RecordTime); /* x-axis */data.setValue(i, 1, P1data); /* Y-axis category #1*/data.setValue(i, 2, P2data); /* Y-axis category #2*/data.setValue(i, 3, P3data); /* Y-axis category #1*/ data.setValue(i, 4, P4data); /* Y-axis category #2*/} /*********************************end of loops***************************************/ var chart = new google.visualization.columnchart(document.getElementById('chart_div')); chart.allowRedraw = true; chart.draw(data, {displayAnnotations: false });} </script>\[/code\]While looking at the source code i get the following value from json_encodevar encoded_P1data =http://stackoverflow.com/questions/10274797/["1111","1234","1111","1111","1234","1111","1111","1234","1111","1111"];\[code\] var encoded_P2data = http://stackoverflow.com/questions/10274797/["2222","2345","2222","2222","2345","2222","2222","2345","2222","2222"]; var encoded_P3data = http://stackoverflow.com/questions/10274797/["3333","3456","3333","3333","3456","3333","3333","3456","3333","3333"]; var encoded_P4data = http://stackoverflow.com/questions/10274797/["4444","4567","4444","4444","4567","4444","4444","4567","4444","4444"]; var encoded_xdata = http://stackoverflow.com/questions/10274797/["10:20:00","10:20:00","10:20:00","10:20:00","10:20:00","10:20:00","10:20:00","10:20:00","10:20:00","10:20:00"];\[/code\]
 
Top