[英]Highchart graph not plotting - CSV
Currently having trouble getting data to display on a highchart. 当前在获取数据以显示在高图上有麻烦。
I'm importing data from a CSV file, and plotting this data. 我正在从CSV文件导入数据,并绘制该数据。 The CSV file takes the format:
CSV文件采用以下格式:
"Row1","Row2","Row3"
"1362567600","67882833572","63034526585"
"1362571200","67834631584","63250345463"
"1362574800","67886235392","63654664341"
"1362578400","67883347248","63683239219"
"1362582000","67884373456","63905665096"
There are 44 elements for each row within the CSV file. CSV文件中的每一行都有44个元素。
I'm currently importing it in the following way: 我目前正以以下方式导入它:
$(document).ready(function() {
var c = [];
var d = [];
var e = [];
$.get('test.csv', function(data) {
var lines = data.split('\n');
$.each(lines, function(lineNo, line) {
var items = line.split(',');
c.push(items[0]);
d.push(items[1]);
e.push(items[2]);
});
createGraph('container', 'line', 'Graph 1', c[0],d[0],c);
});
});
The function createGraph takes the paramaters - divId(Specifying what div to display the graph in; graphType, graphTitle, line1, line2, and graphCategories. 函数createGraph采用参数-divId(指定要在其中显示图形的div; graphType,graphTitle,line1,line2和graphCategories。
I create an array - seriesData[] and use the following for loop to add data to it: 我创建一个数组-seriesData []并使用以下for循环向其添加数据:
seriesData[0] = "[";
for (var i = 1; i < graphCategories.length - 1; i++){
seriesData[i] = "["+(graphCategories[i].replace(/["']{1}/gi,"")*1000)+","+876+"],";
}
seriesData.push("],");
When logging this array on the console it looks like this: 在控制台上记录此数组时,它看起来像这样:
[,[1362567600000,876],,[1362571200000,876],,[1362574800000,876],,[1362578400000,876],,],
Then when plotting the graph I use: 然后在绘制图形时我使用:
series: [{
name: line1,
data: seriesData
}]
(There is another line, but for simplicity I'm just showing the one). (还有另一行,但为简单起见,我只显示其中一行)。
My question is, why is nothing displaying on the graph? 我的问题是,为什么图表上没有任何显示? I get the following output:
我得到以下输出:
Thanks for your help. 谢谢你的帮助。
This line looks wrong. 这行看起来不对。
seriesData[0] = "[";
seriesData.push("],");
I don't think you need to be adding the [ or ] to your array. 我认为您不需要在数组中添加[或]。
I would do it more like this: 我会更像这样:
for (var i = 1; i < graphCategories.length - 1; i++){
// Push the x value.
seriesData[i].push(graphCategories[i].replace(/["']{1}/gi,"")*1000);
// Push the y value.
seriesData[i].push(876);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.