gpt4 book ai didi

javascript - 整个月的排行榜都在跳跃

转载 作者:行者123 更新时间:2023-11-28 07:53:54 26 4
gpt4 key购买 nike

我正在尝试使用 highcharts 绘制散点图。我正确地得到了日期和值(value)。发生的奇怪的事情是,假设我必须在 8 月 5 日到 10 月 25 日之间绘制图表,但它正在绘制 9 月 5 日到 11 月 25 日的数据。整整跳了一个月。

这是我的代码。

var generate_scatter = function(data) {
var range = []
for (a in data['response']){
receive_date = a.split("-");
temp = [Date.UTC(parseInt(receive_date[0]), parseInt(receive_date[1]), parseInt(receive_date[2])),data['response'][a]];
range.push(temp);
}
$('#container').highcharts({
chart: {
type: 'scatter',
zoomType: 'xy'
},
title: {
text: 'Number of packages received in the warehouse against time.'
},
subtitle: {
text: 'Source: MENAERP Database'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%e. %b',
year: '%b'
},
title: {
text: 'Date'
},
startOnTick: true,
endOnTick: true,
showLastLabel: true
},
yAxis: {
title: {
enabled: true,
text: 'Number of packages received in warehouse'
}

},
legend: {
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
x: 100,
y: 70,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF',
borderWidth: 1
},
plotOptions: {
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x:%e. %b}: {point.y:.2f} Packages'
}
}
},
series: [{
name: 'Packages',
color: 'rgba(223, 83, 83, .5)',
data : range
}]
});

};

我已经检查了数据中的所有日期,它们都是正确的。
Firebug 控制台中也没有错误。
怎么了?

附:迭代后范围数组如下所示。

[[1411862400000,127],[1410393600000,162],[1412985600000,278],[1410912000000,147],[1410048000000,172],[1410825600000,177],[1414368000000,362],[1410220800000,180],[1411257600000,143],[1411171200000,324],[1411776000000,178],[1411689600000,210],[1412380800000,189],[1410739200000,8]]

如果您从外部调用它,这里就是实际数据。

{'response' : {'2014-08-28': 127, '2014-08-11': 162, '2014-09-11': 278, '2014-08-17': 147, '2014-08-07': 172, '2014-08-16': 177, '2014-09-27': 362, '2014-08-09': 180, '2014-08-21': 143, '2014-08-20': 324, '2014-08-27': 178, '2014-08-26': 210, '2014-08-25': 148, '2014-09-30': 301, '2014-09-15': 289, '2014-09-14': 177, '2014-09-17': 257, '2014-09-16': 161, '2014-08-05': 198, '2014-09-10': 202, '2014-09-13': 308, '2014-08-06': 175, '2014-10-01': 219, '2014-10-02': 170, '2014-10-06': 390, '2014-10-07': 230, '2014-10-08': 308, '2014-10-09': 209, '2014-08-23': 206, '2014-09-06': 262, '2014-09-07': 257, '2014-08-18': 213, '2014-08-19': 252, '2014-09-02': 194, '2014-09-18': 261, '2014-09-20': 232, '2014-09-21': 214, '2014-09-22': 137, '2014-09-23': 219, '2014-09-24': 184, '2014-09-25': 167, '2014-09-08': 240, '2014-09-09': 349, '2014-09-28': 329, '2014-09-29': 216, '2014-08-10': 205, '2014-08-24': 154, '2014-08-30': 165, '2014-08-31': 263, '2014-08-14': 168, '2014-09-01': 219, '2014-08-12': 134, '2014-10-13': 38, '2014-10-12': 250, '2014-10-11': 305, '2014-08-13': 207, '2014-09-03': 251, '2014-09-04': 189, '2014-08-15': 8}}

最佳答案

似乎 UTC 月份是从 0 开始的。所以这个小技巧可以解决您的问题:

temp = [Date.UTC(parseInt(receive_date[0]), parseInt(receive_date[1])-1,parseInt(receive_date[2])),data['response'][a]];

这里是关于 Date.UTC 的文档

关于javascript - 整个月的排行榜都在跳跃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26376101/

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