Unfortunately, your PHP doesn't help us. Can you post the output js so we
can test it?
On Monday, April 23, 2012 3:23:54 AM UTC-4, Monty wrote:
>
> Hi I am newbiee to google Graph.I am generating arrays from php
> andpassing it to google graph using json_encode method of php but
> getting an error ie Uncaught Error: Invalid type: int. format
> +en,default, annotated timeline +en_US.I.js:53 my code is as follow
>
>
> <?php
>
> $yP1data = 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= 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 = <?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="jsapi.js"></script>
> <script type="text/javascript">
>
>
> google.load('visualization', '1', {'packages':['annotatedtimeline']});
> google.setOnLoadCallback(drawChart);
>
> var P1data = new Array; // This would be the first array passed from
> PHP
> var P2data = new Array; // This would be the second array passed from
> PHP
> var P3data= new Array; // This would be the third array passed from
> PHP
> var P4data = new Array; // This would be the second array passed from
> PHP
> var P5data= new Array;
>
> P1data = encoded_P1data;
> P2data = encoded_P2data;
> P3data= encoded_P3data;
> P4data = encoded_P4data;
> RecordTime= encoded_xdata ;
> function drawChart() { var data = new
> google.visualization.DataTable();
>
> 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[i]); /* x-axis */
> data.setValue(i, 1, P1data[i]); /* Y-axis category #1*/
> data.setValue(i, 2, P2data[i]); /* Y-axis category #2*/
> data.setValue(i, 3, P3data[i]); /* Y-axis category #1*/
> data.setValue(i, 4, P4data[i]); /* 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>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-visualization-api/-/IA6Rc71N_2IJ.
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.