我有那些数据:
var data = {
resultDescription: "SUCCESS",
data: [ ["JAN","1048729"], ["FEB","1220608"],["MAR","1299965"],["APR","1288644"],["MAY","1077342"],["JUN","705690"],["JUL","666131"],["AUG","769444"],["SEP","581618"],["OCT","564438"],["NOV","535066"],["DEC","1241228"]]};
我想把它转换成json,哪个图表会接受。为此,我把它的数据分成2个1d数组:
for(var i = 0; i < data.data.length; i++)
{
newArr = newArr.concat(data.data[i]);
}
for(var i=0; i< newArr.length; i++){
if(i%2==0){
labelsArr = labelsArr.concat(newArr[i]);
}
else{
dataArr = dataArr.concat(newArr[i]);
}
}
var mappedData = data.data.map(function(item) {
return {labels: labelsArr, data: dataArr};
});
但它给了我json格式:
data:Array [12]
标签:数组[12]
但我想要
labels: Array[12], datasets: [{ data: Array[12] }]
我怎样才能做到这一点?
答案 0 :(得分:0)
更改return
语句,如下所示
return { labels: labelsArr, datasets: [ {data : dataArr} ] };