I'm trying to use highchart.js.
here is my code
$.ajax({ type: "POST",
url: "api/getListWeight",
dataType: "json",
data : {idBoxeur : idBoxeur}
}).done(function( dataWeightList ) {
var data = [];
$.each(dataWeightList, function( dataWeightList_index, dataWeightList_value ) {
var splitDateRes = dataWeightList_value.weight_date.split("/");
data.push("["+Date.UTC(splitDateRes[2],parseInt(splitDateRes[1], 10)-1,parseInt(splitDateRes[0], 10))+","+dataWeightList_value.weight_poids+"]");
});
var serie = data.join(",");
}
Code snippet above result something like this :
[1330300800000,76.8],[1347235200000,78.8],[1347580800000,77.4]
just like expected.
Now chart
$('#graph').highcharts({
chart: {
type: 'spline',
zoomType: 'x'
},
xAxis: {
type: 'datetime'
},
series: [{
name: 'serie Name',
data: [
//pass serie from snippet above
serie
]
}]
});
Result : nothing happened..Chart is empty.
Only thing that i'm pretty sure, if i replace serie
by [1330300800000,76.8],[1347235200000,78.8],[1347580800000,77.4],[1348444800000,76.8]
inside my code, it work like a charm.
What i'm doing wrong ? How can i solve it ?
Thx for reading
You are passing string while should be JS object.
That line:
data.push("["+Date.UTC(splitDateRes[2],parseInt(splitDateRes[1], 10)-1,parseInt(splitDateRes[0], 10))+","+dataWeightList_value.weight_poids+"]");
should be:
data.push([Date.UTC(splitDateRes[2],parseInt(splitDateRes[1], 10)-1,parseInt(splitDateRes[0], 10)),dataWeightList_value.weight_poids]);
And this line:
var serie = data.join(",");
what is for? Remove that line or at least remove that join, please.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.