主要是背景查詢資料放到json裡的形式,和前台如何取出json
<td style="width:35%;padding:0px;">
<div id="qingTuiTJ" style="width: 100%;height:220px;"></div>
<script type="text/javascript">
// 基于準備好的dom,初始化echarts執行個體
var myChart22 = echarts.init(document.getElementById('qingTuiTJ'));
var option22 = {
title : {
text: '${yearMonth!''}清退統計',
subtext: '',
x:'right'
},
tooltip : {
trigger: 'item',
formatter: "{b} : {c} ({d}%)"
},
legend: {
orient: 'vertical',
left: 'left',
data: ['逾時清退','按時清退','尚未清退','無需清退']
},
series : [
{
name: '通路來源',
type: 'pie',
radius: ['50%', '70%'],
center: ['58%', '58%'],
data:[],
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
// 使用剛指定的配置項和資料顯示圖表。
myChart22.setOption(option22);
$(function(){
$.post("./countNumByMonth",{},function(result){
var nums=[];
$.each(result.obj,function(key,values){ //此處我傳回的是list<String,map<String,String>>循環map
var obj = new Object();
obj.name = values.name;
obj.value = values.value;
nums.push(obj);
});
myChart22.setOption({
series: [{
data: nums
}]
});
},"json");
});
</script>
</td>
背景代碼:
@ResponseBody
@RequestMapping(value = "/countNumByMonth", method = { RequestMethod.POST, RequestMethod.GET })
public Json countNumByMonth(
HttpServletRequest request, HttpServletResponse response, ModelMap model
){
Json json = new Json();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
String yearMonth = sdf.format(new Date());
json.setSuccess(true);
List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
Map<String,Object> map1 = new HashMap<String,Object>();
EntityWrapper<GwdjIdeainfo> wrapper1 = new EntityWrapper<GwdjIdeainfo>();
wrapper1.like("SI_SEND_TIME", yearMonth, SqlLike.RIGHT);
wrapper1.eq("SI_STATE", "3");
map1.put("name", "逾時清退");
map1.put("value", gwdjIdeainfoServiceImpl.selectCount(wrapper1));
Map<String,Object> map2 = new HashMap<String,Object>();
EntityWrapper<GwdjIdeainfo> wrapper2 = new EntityWrapper<GwdjIdeainfo>();
wrapper2.like("SI_SEND_TIME", yearMonth, SqlLike.RIGHT);
wrapper2.eq("SI_STATE", "2");
wrapper2.where("SI_QTTYPE!='0'");
map2.put("name", "按時清退");
map2.put("value", gwdjIdeainfoServiceImpl.selectCount(wrapper2));
Map<String,Object> map3 = new HashMap<String,Object>();
EntityWrapper<GwdjIdeainfo> wrapper3 = new EntityWrapper<GwdjIdeainfo>();
wrapper3.like("SI_SEND_TIME", yearMonth, SqlLike.RIGHT);
wrapper3.eq("SI_STATE", "1");
map3.put("name", "尚未清退");
map3.put("value", gwdjIdeainfoServiceImpl.selectCount(wrapper3));
Map<String,Object> map4 = new HashMap<String,Object>();
EntityWrapper<GwdjIdeainfo> wrapper4 = new EntityWrapper<GwdjIdeainfo>();
wrapper4.like("SI_SEND_TIME", yearMonth, SqlLike.RIGHT);
wrapper4.eq("SI_STATE", "2");
wrapper2.eq("SI_QTTYPE", "0");
map4.put("name", "無需清退");
map4.put("value", gwdjIdeainfoServiceImpl.selectCount(wrapper4));
resultList.add(map1);
resultList.add(map2);
resultList.add(map3);
resultList.add(map4);
json.setObj(resultList);
return json;
}