You could use php's file() function to read the file's contents into an
array, and then output the data as a javascript array. Something like this
would do it:
<?php
// foo.csv is the CSV file
$file = file("path/to/foo.csv");
// $arr is an array of javascript arrays
$arr = array();
// $i is the index for the x-axis
$i = 0;
foreach ($file as $row) {
$arr[] = "['$i', $row]";
$i++;
}
// $js is the final javascript array
$js = '['. implode(',', $arr). ']';
?>
// javascript chart drawing function
function drawChart () {
var data = new google.visualization.DataTable();
data.addColumn("string", "index");
data.addColumn("number", "foo");
// insert js array
data.addRows(<?php echo $js; ?>);
var chart = new
google.visualization.LineChart(document.getElementById("chart_div"));
chart.draw(data, <options>);
}
--
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.