Google Vizualization with CSV data
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 gene开发者_运维知识库ral.
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.
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:
converting CSV/XLS to JSON?
精彩评论