我想加载 x csv 文件并将数据呈现为折线图。加载 1 个 csv 文件并创建折线图已经很好了。
我的 csv 文件:
Date,PV,Energy
1355100420,0.000,0.851
1355100480,0.000,0.841
1355100540,0.000,1.000
1355100600,0.000,0.984
1355100660,0.000,1.006
1355100720,0.000,2.769
1355100780,0.000,2.791
我的问题:csv 文件的数量多种多样,正确的顺序很重要,因为 x 轴是我的时间轴,我的 csv 的第一列中有日期/时间。
读取单个 csv:
$.get(csv_file, function(data) {
var series = [];
// Split lines
var lines = data.toString().split('\n');
// For each line, split the record into seperate attributes
$.each(lines, function(lineNo, line) {
var items = line.split(',');
// first line contains the series names
if (lineNo === 0) {
for (var i = 1; i < items.length; i++) {
series.push({
name : items[i],
data : [],
dataGrouping : {
enabled : false
}
});
}
} else {
for (var i = 1; i < items.length; i++) {
// get the serie
var serie = series[i - 1];
serie.data.push([parseFloat(items[0] * 1000), parseFloat(items[i])]);
}
}
});
chart = new Highcharts.StockChart({
chart : {
renderTo : container_id,
type : 'line',
reflow : true,
},
xAxis : {
type : 'datetime'
},
series : series
});
});
但是我怎样才能以正确的顺序读取多个 csv 文件呢?
非常感谢!