我在基于 WEB 的系统上工作,我正在使用 amcharts.com 的 JavaScript 应用程序来创建一个图形,该图形从 CVS 文件中获取其值并解析它们,然后绘制它们。在 CSV 我有时间和价值列。时间格式为时:分:秒。例如时间列中的值可以是 5:07:38
这里是解析数据的部分:
// method which parses csv data
function parseCSV(data){
//replace UNIX new lines
data = data.replace (/\r\n/g, "\n");
//replace MAC new lines
data = data.replace (/\r/g, "\n");
//split into rows
var rows = data.split("\n");
// create array which will hold our data:
dataProvider = []
// loop through all rows
for (var i = 1; i < rows.length; i++){
// this line helps to skip empty rows
if (rows[i]) {
// our columns are separated by comma
var column = rows[i].split(",");
// column is array now
// first item is date
var date = column[2];
// second item is value of the second column
var value1 = column[3];
// create object which contains all these items:
var dataObject = {date:date, value1:value1};
// add object to dataProvider array
dataProvider.push(dataObject);
}
}
// set data provider to the chart
chart.dataProvider = dataProvider;
// this will force chart to rebuild using new data
chart.validateData();
}
结果,我得到了混合时间地点的图形。例如:
5:19:11 5:03:12 5:05:12 5:07:12 5:12:11 5:14:11 5:16:11 5:18:11
有什么想法可以让它们像在 CSV 文件中那样按正确的顺序排列吗?