1、echars饼状图返回的数据格式
[
{
"name": "A",
"value": 3
},
{
"name": "B",
"value": 2
},
{
"name": "C",
"value": 2
}
]
java代码Demo 为例:根据名字分组,统计数量
public JSONArray demoBingTuTotal(){
//查询需要返回的数据,根据自己的数据来写
List<Demo> demoList= demoService.selectList(new Demo());
Map<String, Long> collect =
demoList.stream().collect(Collectors.groupingBy(Demo::getName, C
ollectors.counting()));
JSONArray jsonArray = new JSONArray();
collect.forEach((name, count) -> {
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", name);
jsonObject.put("value", count);
jsonArray.add(jsonObject);
});
return jsonArray;
}
2、echars柱状图返回的数据格式
{"name": ["A","B"],"count": [2,2]}
java Demo代码为例: 根据名字分组,统计数量count的和
public Map<String,Object> zhuTuTotal(){
//查询需要返回的数据,根据自己的数据来写
List<Demo> demos= demoService.selectList(new Demo());
Map<String, Long> collect =
demos.stream().collect(Collectors.groupingBy(Demo::getName,Collectors.reducing(0L,
Demo::getCount, Long::sum)));
HashMap<String,Object> map = new HashMap<String, Object>();
map.put("name",collect.keySet());
map.put("count",collect.values());
return map;
}