Google Visualization Api + SQL

210 views
Skip to first unread message

Gareth Jones

unread,
Nov 7, 2009, 4:54:20 AM11/7/09
to Google Visualization API
Hi,

I'd like to create a Google Vizualization of some data in a MySql
Database and I'm having problems.

Here is the source so far:

<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
connecting to mysql');
mysql_select_db($dbname);
$int_y_pos = -1;
$int_y_step_small = 1;
$sql = "SELECT * from table')";
$sql = mysql_query($sql);
$rownum = mysql_num_rows($sql);
?>
<html>
<head>
<script type="text/javascript" src="http://www.google.com/
jsapi"></
script>
<script type="text/javascript">
google.load("visualization", "1", {packages:
["table"]});
google.setOnLoadCallback(drawData);
function drawTable() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'column1');
data.addColumn('string', 'column2');
<?php
echo " data.addRows($rownum);\n";
while($row = mysql_fetch_assoc($sql)) {
$int_y_pos += $int_y_step_small;
echo " data.setValue(" . $int_y_pos . ", 0, new column1
(" .
$row['column1'] . "));\n";
echo " data.setValue(" . $int_y_pos . ", 0, new column2
(" .
$row['column2'] . "));\n";
}

?>

Any help or examples of previous previous integrations would be great.

Thanks

Gareth

rcrisman

unread,
Nov 9, 2009, 8:21:21 AM11/9/09
to Google Visualization API

Markw65

unread,
Nov 9, 2009, 9:57:15 AM11/9/09
to Google Visualization API
If you want a more complete solution (and most likely significantly
faster for large datasets), I wrote a google datasource library in
php. It supports the full datasource query language, and has a built
in wrapper for mysql.

You can find the project here: http://code.google.com/p/vis-table,
with details of how to integrate with a mysql database here:
http://code.google.com/p/vis-table/wiki/mysql_vistable.

Mark

On Nov 9, 5:21 am, rcrisman <rcris...@tentec.com> wrote:
> Here is how I did it.  I suggest you pay close attention to the SQL
> query.
>
> http://groups.google.com/group/google-visualization-api/browse_thread...
Reply all
Reply to author
Forward
0 new messages