我不是很精通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);
        });


    });

最佳答案

尝试从更改代码

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



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

您的问题可能与csv文件中的回车符有关

关于javascript - 如何解决highstocks错误#15,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21344005/

10-11 23:33