开发者

Google Vizualization with CSV data

开发者 https://www.devze.com 2022-12-24 22:50 出处:网络
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

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消