[英]Highchart.js pass array doesnt work
I'm trying to use highchart.js. 我正在尝试使用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. 我唯一确定的事情是,如果我在代码中用
[1330300800000,76.8],[1347235200000,78.8],[1347580800000,77.4],[1348444800000,76.8]
代替serie
,它就像一个魅力。
What i'm doing wrong ? 我做错了什么? How can i solve it ?
我该如何解决?
Thx for reading 阅读Thx
You are passing string while should be JS object. 您正在传递字符串,而应该是JS对象。
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.
请删除该行或至少删除该连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.