Json传到前到的数据如下 :
[
{"unitdesc":" 作品为主,同时兼备***馆的各项功能。",
"unitheatTotal":0,
"unitcoldTotal":1176.02,
"unitwaterTotal":0,
"unitpicturename":"",
"datas":{"2016":["8251.41","7075.39","0.0","0.0","0.0","1176.02","0.0"],"2015":"0.0","0.0","0.0","0.0","0.0","0.0","0.0"],
"2010":"80.0","0.0","0.0","0.0","0.0","0.0","0.0"],"2018":"900","0.0","0.0","0.0","0.0","0.0","0.0"]},
"unitairTotal":0,
"unitelectricTotal":7075.39,
"unitname":"关伙馆",
"unitotherTotal":0,
"unitId":0,
"id":666666,
"unitTotal":8251.4},
{"unitdesc":" 队**层群众文化建设,活跃群众文化生活***军的作用。",
"unitheatTotal":0,
"unitcoldTotal":0,
"unitwaterTotal":0,
"unitpicturename":"",
"datas":{"2016":["4618.09","4618.09","0.0","0.0","0.0","0.0","0.0"],"2015":["0.0","0.0","0.0","0.0","0.0","0.0","0.0"],
"2010":"400","0.0","0.0","0.0","0.0","0.0","0.0"],"2018":"980","0.0","0.0","0.0","0.0","0.0","0.0"]},
"unitairTotal":0,
"unitelectricTotal":4618.08984375,
"unitname":"燕学处",
"unitotherTotal":0,
"unitId":0,
"id":666667,
"unitTotal":4618.08984375
}
]
现在要把集合中每个对象的属性为datas(map集合)的值。按Map中的key 从小到大的顺序排列。;
ajax成功后的解析上面的数据-----------(Highchart中)---------
success : function(data) {
var cityenergymonitorVos=JSON.parse(data);
//alert(data);
var xAxisValues=[];// 定义X轴的内容
var series=[];//定义数据
//id为cityenergy里的数据。。总的要求和
var alltotaldian=0;
var alltotalwater=0;
var alltotalair=0;
var alltotalheat=0;
var piedata=[];// 饼图的数据
//对单位集合循环取数据---------开始------------------
for (var int = 0; int < cityenergymonitorVos.length; int++) {
var cityenergymonitor=cityenergymonitorVos[int];
var datas=cityenergymonitor.datas;
var obj = new Object();
xAxisValues=[];//只取最后一次的key
//id为cityenergy里的数据。。总的要求和
alltotaldian=alltotaldian+cityenergymonitor.unitelectricTotal;
alltotalwater=alltotalwater+cityenergymonitor.unitwaterTotal;
alltotalair=alltotalair+cityenergymonitor.unitairTotal;
alltotalheat=alltotalheat+cityenergymonitor.unitheatTotal;
var unitpie=[];//饼图数据添加。。。
unitpie.push(cityenergymonitor.unitname);
unitpie.push(parseFloat(cityenergymonitor.unitTotal));
piedata.push(unitpie);
obj.name=cityenergymonitor.unitname;
obj.data=[];
//---------------------datas--Map集合按key排序。并添加数据到series的Obj(unit单位)中。-----
var objectList = new Array();
function sersis(mykey,mydata){
this.mykey=mykey;
this.mydata=mydata;
}
for (var key in datas) {
objectList.push(new sersis(key,datas[key]));
}
//按日期从小到大排序
objectList.sort(function(a,b){
return a.mykey-b.mykey;});
for (var j = 0; j < objectList.length; j++) {
var thisobj=objectList[j];
xAxisValues.push(parseInt(thisobj.mykey));
obj.data.push(parseFloat(thisobj.mydata[0]));
}
series.push(obj);
//-------------datas--Map集合按key排序。并添加数据到当前Obj(unit单位)中-----结束---------
//other code.....
}//对单位集合循环取数据---------结束------------------
}
//------------------------------------------------
// 到前台数据的对应该的VO。
public class CityenergyMonitorVO extends BaseVO {
private int unitId; //单一的单位ID
private String unitname;//单位的名称
private String unitdesc;//单位的描述
private String unitpicturename;//单位图片名称
private float unitelectricTotal=0;
private float unitwaterTotal=0;
private float unitairTotal=0;
private float unitheatTotal=0;
private float unitcoldTotal=0;
private float unitotherTotal=0;
private float unitTotal=0;
//(key1--电,[电的各数据])(key2--水,[水的各数据])(key3--气,[气的各数据])(key4--热,[热的各数据]) ......
private Map
//getter and setters---------------
}