score:4

Accepted answer

so, you have the following data structure, right ?

1355417598678,22.25
1355417620144,22.25
1355417625616,22.312
1355417630851,22.375
1355417633906,22.437
1355417637134,22.437
1355417641239,22.5
1355417641775,22.562
1355417662373,22.125
1355417704368,21.625

then you split it into an array of lines, so each array item is a line.
then for each line you do the following.

var items = line.split(';'); // wrong, use ','

but there ins't ; into the line, you should split using ,.
the result will be a multidimencional array which each item is an array with the following structure. it will be stored in a var named data.

"1355417598678","22.25" // date in utc, value

this is the expected data for each serie, so you can pass it directly to your serie.

var serie = {
    data: data,
    name: 'serie1' // chose a name
}

the result will be a working chart.

so everything can be resumed to the following.

var lines = data.split('\n');
lines = lines.map(function(line) {
    var data = line.split(',');
    data[1] = parsefloat(data[1]);
    return data;
});

var series = {
    data: lines,
    name: 'serie1'
};
options.series.push(series);

score:0

you need to put

    $(document).ready(function() {

in the 1st line, and

     });

in the last line of the javascript to make this work.

score:0

could you upload your csv file? is it identical to what you wrote in your original post? i ran into the same problem, and it turns out there are errors in the data file.

score:1

looking at your line.split part:

$.get('data.csv', function(data) {
        // split the lines
        var lines = data.split('\n');
        $.each(lines, function(lineno, line) {
            var items = line.split(';');

it looks like you are trying to split on a semi-colon (;) instead of a comma (,) which is what is in your sample csv data.


Related Query

More Query from same tag