“请问有人能够指导我如何获取这样的JSON对象日期时间吗?”
将日期时间转换为适合在Highcharts中使用的javascript格式。
更新:
这是我正在尝试做的事情:
这是在 jsFiddle 上的链接:here。
我得到的结果是 [[1357027200000,5.5]],这很好用。
{
value="01/01/2013 08:00",
key=5.5
}
将日期时间转换为适合在Highcharts中使用的javascript格式。
[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]
]);
});
这是在 jsFiddle 上的链接:here。
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]],这很好用。
{value="01/01/2013 08:00", key=5.5}
不是有效的 JSON 格式,它是从哪里来的?如果它是有效的 JSON,你要将其转换为数组,例如[Date.UTC(2013, 0, 1,08,00), 4.4]
,但是 4.4 是从哪里来的?你是不是想表达的是 5.5? - Mark