I am trying to draw a column chart from MySQL database. I've just
started playing around with google visualisation in the code
playground and have managed to change the column chart to what i want
my chart to be. But as soon as i start putting php in the code the
chart disappears. I know i am doing something wrong - but have no idea
what. Couldn't find an answer or a detailed (for dummies) tutorial in
the forum or google search. I think the var = conc values should be
the values from query result, but its not working.
Here is the code - would appreciate any help. Thanks.
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
<?php $query = "SELECT * FROM sample_conc ";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) { ?>
var conc = [['A', 11, 12, 2, 7, 3, 5 ],
['B', 8, 5, 13, 8, 4, 6 ],
['C', 7, 6, 11, 9, 5, 6 ],
['D', 10, 3, 12, 10, 8, 5 ],
['E', 10, 3, 9, 11, 6, 8 ],
['F', 9, 4, 6, 12, 5, 9 ]];
<?php } ?>
var sample = [0, 1, 2, 3, 4, 5];
data.addColumn('string', 'sample');
for (var i = 0; i < conc.length; ++i) {
data.addColumn('number', conc[i][0]); }
data.addRows(sample.length);
for (var j = 0; j < sample.length; ++j) {
data.setValue(j, 0, sample[j].toString()); }
for (var i = 0; i < conc.length; ++i) {
for (var j = 1; j < conc[i].length; ++j) {
data.setValue(j-1, i+1, ms_conc[i][j]);
}
}
// Create and draw the visualization.
new
google.visualization.ColumnChart(document.getElementById('visualization')).
draw(data,
{title:"Concentrations by sample",
width:650, height:380,
vAxis: {title: "Concentrations"},
hAxis: {title: "Samples"}}
);
}
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
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.