我一直在使用Google Charts API玩弄折線圖,下面的例子顯示了一個多維數組被填充到數據表中,然後顯示在屏幕上。CSV轉換爲多維數組。怎麼樣?
它工作的很好,但我希望能夠從可能包含n個列的相同文件夾中找到的CSV文件中填充數據。
任何人都可以幫助解決這個問題嗎?
我想用jQuery .get訪問csv文件,然後將其轉換爲數組。我只是不很精明的JS時下..
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
]);
var options = {
title: 'Company Performance'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
建立一個你的'csv'數據的例子 – sabithpocker
這個例子就像google示例中顯示的數組一樣。 – ASPiRE