我有一个 CSV 文件:
2011-01-11, 0:00, 4
2011-01-11, 0:05, 2
2011-01-11, 0:10, 6
2011-01-11, 0:15, 8
...
2011-01-12, 0:00, 4
2011-01-12, 0:05, 2
...
2011-01-13, 20:00, 4
2011-01-13, 20:05, 2
...
仅显示最近 48 小时数据的最佳做法是什么?
这是 CSV 解析器:
$.get('data.csv', function(data) {
// Split the lines
var lines = data.split('\n');
$.each(lines, function(lineNo, line) {
var items = line.split(',');
// header line containes categories
if (lineNo == 0) {
$.each(items, function(itemNo, item) {
if (itemNo > 0) options.xAxis.categories.push(item);
});
}
// the rest of the lines contain data with their name in the first position
else {
var series = {
data: []
};
$.each(items, function(itemNo, item) {
if (itemNo == 0) {
series.name = item;
} else {
series.data.push(parseFloat(item));
}
});
options.series.push(series);
}
});
修改此解析器以仅从 CSV 加载最后 288 行(24 小时数据)是一种好方法吗?如果是,我该怎么做?