views:

454

answers:

1

Hi,

I have a URL that returns data in CSV format. I would like to use Google Vizualization to create an interactive chart of the data. I've looked at several examples on Google Chart and Vizualization web page but I'm a bit confused as I'm not familiar with JavaScript or web programming in general.

Question: Do I have to use JavaScript to parse the CSV string myself and manually construct the DataTable with addColumn() and addRows()? Or, is there a way to simply pass the CSV url to the charting function? I'm hoping to do something like this:

var csv_data = get_data_from_url('http://...')
var data = new google.visualization.DataTable(csv_data);
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, ...);

Can someone please help me out?

Thanks.

+1  A: 

Yeah, it looks like they're using JSON or some close variant of JSON for the data. You could try a CSV to JSON converter. Apparently converting CSV to JSON is a fairly trivial operation, requiring only a few lines of code:

http://stackoverflow.com/questions/662859/convert-csv-xls-to-json

Robert Harvey
Thanks for the response. I looked at the documentation on data sources:http://code.google.com/apis/visualization/documentation/dev/implementing_data_source.html#responseformatand it looks like the java.visualization.Query only takes JSON format.... I'm hesitant to use the CSV to JSON link because i don't want to expose the data to the outside.
Shlomo Shmai
Well, you could process it server side. You can roll code any way you want with this; all of the examples I've seen only require about a dozen lines of code to perform the conversion.
Robert Harvey