Ok, here's your basic structure:

<?php 
$username = 'mysql username';
$password = 'mysql password';
$databasename = 'mysql database name';

try {
$db = new PDO("mysql:dbname=$databasename", $username, $password);
}
catch (PDOException $e) {
die("{error: {$e->getMessage()}}");
}
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$query = $db->prepare("SELECT column1, column2, etc... FROM myTable");
try {
$query->execute();
$results = $query->fetchAll(PDO::FETCH_ASSOC);
}
catch (PDOException $e) {
die("{error: {$e->getMessage()}}");
}

$table = array(
'cols' => array(
array('label' => 'Column 1' , 'type' => '<column 1 data type>'),
array('label' => 'Column 2' , 'type' => '<column 2 data type>')
// etc
),
'rows' => array()
);

foreach ($results as $r) {
$table['rows'][] = array('c' => array(
array('v' => $r['column1']),
array('v' => $r['column2'])
// etc
));
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>My Chart</title>
<script type='text/javascript' src="http://www.google.com/jsapi";></script>
<script type='text/javascript'>
//<![CDATA[ 
function drawChart () {
var data = new google.visualization.DataTable(<?php echo 
json_encode($table, JSON_NUMERIC_CHECK); ?>);
 var chart = new 
google.visualization.LineChart(document.querySelector('#chart_div'));
chart.draw(data, {
height: 400,
width: 600
});
}
google.load('visualization', '1', {packages:['corechart'], callback: 
drawChart});
//]]>  
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>

On Friday, November 8, 2013 5:00:19 PM UTC-5, Nelson Idachi wrote:
>
> i think i will go with the first option. Can you guide me through that?
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to