如何解决highstocks错误#15

时间:2014-01-24 22:56:16

标签: javascript highcharts highstock

我对javascript的熟练程度不高,但我设法拼凑了这段代码,用于绘制我的数据图,但我收到错误#15(Highcharts预计数据会是排序)。我已经四处寻找,但在具体情况下我需要帮助来解决这个问题。

这是我的代码,其中包含.csv数据的示例:

        $(document).ready(function() {


        var options = {

            chart: {
                renderTo: 'container',
                type: 'line'
            },

            title: {
                text: 'Temperature'
            },

            xAxis: {
                categories: []
            },

            yAxis: {
                title: {
                    text: 'Temp'
                }
            },
            series: []
        };

  /* 
     Data Series in .csv file are in columns, e.g.:

     1/24/2014 12:00:29 AM,74.64
     1/24/2014 12:01:29 AM,74.75
     1/24/2014 12:02:29 AM,74.86
     1/24/2014 12:03:29 AM,74.98
     1/24/2014 12:04:29 AM,74.98
     1/24/2014 12:05:29 AM,75.09
     1/24/2014 12:06:29 AM,75.09

     */

        $.get('temp2.log', function(data) {

            var lines = data.split('\n');

            lines = lines.map(function(line) {

                var data = line.split(',');

                sections = data[0].split(' ');
                section1 = sections[0].split('/');

                mm = parseInt(section1[0]-1);
                dd = parseInt(section1[1]);
                yyyy = parseInt(section1[2]);

                section2 = sections[1].split(':');

                hh = parseInt(section2[0]);
                mi = parseInt(section2[1]);
                ss = parseInt(section2[2]);

                section3 = sections[2];

                if(section3 == 'AM') hh = hh;
                if(section3 == 'PM') hh = hh + 12;

                formatDate = Date.UTC(yyyy, mm , dd, hh, mi, ss);

                /* console.log(formatDate); */

                data[0] = formatDate;
                data[1] = parseFloat(data[1]);

                return data;

                });


            var series = {
                data: lines,
                name: 'temp'
            };

            options.series.push(series);

                var chart = new Highcharts.StockChart(options);
        });


    });

1 个答案:

答案 0 :(得分:0)

尝试从

更改代码

var lines = data.split('\n');

var lines = data.split(/\r\n|\n/);

你的问题可能出在csv文件中的回车