The way I did it was roughly as follows:
1. Query your mysql data as you normally would
2. Determine whether your result set fields need to be strings or numbers for visualization api purposes
3. Dynamically generate the javascript code
a. Define the fields as string or number based on step 2
a. Loop through the mysql result set and for each row generate an addRow statement for your data object
Here's a code snippet from what I did to build the function:
<?php
echo "function drawViz()
{\n";
echo "var data = new google.visualization.DataTable();\n";
$resultset = mysql_query( /* your SQL goes here */ ) or die(mysql_error());
$cnt = mysql_num_fields($resultset);
for ($colnum=0; $colnum < $cnt; $colnum++)
{
$sqlFieldType = mysql_field_type($resultset,$colnum);
$fieldvar = getChartFieldType($sqlFieldType);
echo "data.addColumn('" .$fieldvar . "', '" . mysql_field_name($resultset,$colnum) .
"');\n";
}
while ($rowval = mysql_fetch_array($resultset)) {
$rowContents = "[";
for ($colnum=0; $colnum < $cnt; $colnum++)
{
if (mysql_field_type($resultset,$colnum) == "string") $rowContents = $rowContents . "'" . $rowval[$colnum] . "'";
else $rowContents = $rowContents . $rowval[$colnum];
if ($colnum == $cnt - 1) $rowContents = $rowContents . "]";
else $rowContents = $rowContents . ",";
}
echo "data.addRow($rowContents);\n";
}
?>
Of course you need to issue the onCall() and include a div to contain your chart.
HTH,
Bruce