gpt4 book ai didi

javascript - 如何解决 highstocks 错误 #15

转载 作者:行者123 更新时间:2023-11-28 08:34:58 24 4
gpt4 key购买 nike

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


});

最佳答案

尝试更改您的代码

varlines = data.split('\n');

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

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

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com