gpt4 book ai didi

json 日期格式转换为 Highcharts 日期格式

转载 作者:行者123 更新时间:2023-12-01 18:23:40 26 4
gpt4 key购买 nike

请有人指导我如何获取这样的 json 对象日期时间

 {
value="01/01/2013 08:00",
key=5.5
}

转为 javascript(在 Highcharts 中使用)日期时间可接受的格式

[Date.UTC(2013, 0, 1,08,00), 5.5].

更新

这是我正在尝试做的事情:

var chart;

$(document).ready(function () {

chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
zoomType: 'x'
},
yAxis: {
type: 'double',
min: 0
},
xAxis: {
type: 'datetime',
labels: {
formatter: function () {
return Highcharts.dateFormat('%a %d %b %H:%M', this.value);
},
dateTimeLabelFormats: {
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
}
}
},
series: [{
name: 'MyData1',
data: []
}, {
name: 'MyData2',
data: []
}]

});

chart.series[0].setData([
[Date.UTC(2013, 0, 1, 08, 00), 4.4],
[Date.UTC(2013, 0, 1, 12, 00), 6.0],
[Date.UTC(2013, 0, 1, 17, 00), 7.7],
[Date.UTC(2013, 0, 1, 22, 00), 5.8]
]);
chart.series[1].setData([
[Date.UTC(2013, 0, 1, 08, 30), 0.4],
[Date.UTC(2013, 0, 1, 10, 00), 0.0],
[Date.UTC(2013, 0, 1, 16, 00), 0.7],
[Date.UTC(2013, 0, 1, 20, 00), 0.8]
]);
});

here是在 jsFiddle 中吗?

var datatype1=[];
var datatype2= [];

for(index in userReadingsJsonCollection.items){
if(userReadingsJsonCollection.items[index].ReadingsData.Reading_Type==type1){
datatype1.push(
[Date.parse(userReadingsJsonCollection.items[index].ReadingsData.Rec_DateTime),
userReadingsJsonCollection.items[index].ReadingsData.Reading]
);
}
if(userReadingsJsonCollection.items[index].ReadingsData.Reading_Type==type2){
datatype2.push(
[userReadingsJsonCollection.items[index].ReadingsData.Rec_DateTime,
userReadingsJsonCollection.items[index].ReadingsData.Reading]
);
}
}

我得到的结果是 [[1357027200000,5.5]],效果很好。

最佳答案

如果您的时间已经是 UTC,那么就很简单:

Date.parse("01/01/2013 08:00")

编辑

假设您的数据以有效的 JSON 形式返回:

var jsonObj = {value:"01/01/2013 08:00", key:5.5}; 

var seriesOneData = [];
seriesOneData.push([Date.parse(jsonObj.value),jsonObj.key]);

关于json 日期格式转换为 Highcharts 日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14668729/

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