/ / formato de data json para formato de data Highcharts - json, datetime, highcharts

json formato de data para formato de data de Highcharts - json, datetime, highcharts

Poderia, por favor, alguém me guiar como obter esse datetime objeto json

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

para javascript (para usar em Highcharts) formato aceitável de data e hora

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

ATUALIZAR

Aqui está o que estou tentando fazer:

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]
]);
});

Aqui está em 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]
);
}
}

O resultado obtido é [[1357027200000,5.5]] e isso funciona muito bem.

Respostas:

11 para resposta № 1

Se seu horário já é UTC, é tão simples quanto:

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

EDITOS

Supondo que seus dados retornem como JSON válido:

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

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