Re: Google charts are not displaying with new release

83 views
Skip to first unread message
Message has been deleted
Message has been deleted

Qurat Haider

unread,
Nov 28, 2013, 11:00:10 AM11/28/13
to google-visua...@googlegroups.com
This is the my code i am using for column chart before the new release of Google Api and it is working fine. Now my chart is not displaying. i have checked the new release changes but i found noting relevant. the first problem appears with the data type in array, float data type is not legal and if i replaced it with some other data type then chart still not displayed. if i change the float to string then error will appear that string data type will not be used on X-axis. I have plotted time on X-axis and Distance on Y-axis. If any one knows how to change the code according to new release of Google Api please share your code or some information.


 // Connect to server and select database.
 $con=mysql_connect("$host", "$username")or die("cannot connect");
 mysql_select_db("$db_name")or die("cannot select DB");

 $data = mysql_query("select SUM(Distance) as Distance, CAST( Time AS date) as Time from gprs where DeviceId=25 and Time between '2013-08-08' and '2013-09-31' group by CAST(Time AS date) order by CAST( Time AS date)")
 or die(mysql_error()); 

 $table = array();
 $table['cols'] = array(

    array('label' => 'TIME', 'type' => 'string'),
array('label' => 'Distance', 'type' => 'float') 
 );
$rows = array();
while ($nt = mysql_fetch_assoc($data))

{

$temp = array();
$temp[] = array('v' => (string)$nt['TIME']);
$temp[] = array('v' =>(float) $nt['Distance']);
    $rows[]['c'] = $temp;
 }
    $table['rows'] = $rows;
    $jsonTable = json_encode($table);
 ?>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
 <title>
 Google Visualization API Sample
 </title>
 <script type="text/javascript" src="//www.google.com/jsapi"></script>
 <script type="text/javascript">
 google.load('visualization', '1', {packages: ['corechart']});
 </script>
 <script type="text/javascript">
 function drawVisualization() {
 // Create and populate the data table.
 var data = new google.visualization.DataTable(<?=$jsonTable?>);

 // Create and draw the visualization.
 new google.visualization.ColumnChart(document.getElementById('visualization')).
    draw(data);
  }

  google.setOnLoadCallback(drawVisualization);  
 </script>
 </head>
 <body style="font-family: Arial;border: 0 none;">
 <div id="visualization" style="width: 600px; height: 300px;"></div>
 </body>
 </html>

asgallant

unread,
Nov 28, 2013, 8:50:08 PM11/28/13
to google-visua...@googlegroups.com
The appropriate type is "number", which works for both floating-point and integer numbers (as all numbers are floats in javascript).

Qurat Haider

unread,
Nov 29, 2013, 10:14:29 AM11/29/13
to google-visua...@googlegroups.com
Thanks for your reply, my problem is solved now my chart is displaying properly


--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/-T4SrwPf1uM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages