0

Currently having trouble getting data to display on a highchart.

I'm importing data from a CSV file, and plotting this data. The CSV file takes the format:

"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.

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.

I create an array - seriesData[] and use the following for loop to add data to it:

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:

Highchart Example

Thanks for your help.

4

1 回答 1

1

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);
}
于 2013-03-11T10:32:25.300 回答