我有这样的结构
var finalJson = [{"values":[{"x":1444748400000,"y":223696},{"x":1444759200000,"y":7178}],"key":"first_value"},{"values":[{"x":1444748400000,"y":216022},{"x":1444759200000,"y":4996}],"key":"second"},{"values":[{"x":1444759200000,"y":572}],"key":"third"},{"values":[{"x":1444748400000,"y":2446},{"x":1444759200000,"y":60}],"key":"Fourth"},{"values":[{"x":1444737600000,"y":22178},{"x":1444748400000,"y":15864},{"x":1444759200000,"y":540}],"key":"fifth"},{"values":[{"x":1444748400000,"y":8446},{"x":1444759200000,"y":116}],"key":"Sixth"},{"values":[{"x":1444759200000,"y":50}],"key":"seventh"}}] ;
实际上我应该从json结构计算给定时间范围的y值之和,该结构的键为第五个到第七个 现在我已经编写了计算它的代码
var Arr1 = [];
var newJson_forFinalArr = [];
if(Arr1.length>5) {
for(var k=0;k<finalJson.length;k++){
for(var m=5;m<Arr1.length;m++){
sum += Number(finalJson[m].values[k].y);
Arr1[m].values.push({"y":sum,"x":finalJson[m].values.x });
newJson_forFinalArr.push(Arr1[m]);
console.log("data found :: "+JSON.stringify(Arr1));
}
}
}
但总和并没有按要求发生