<%@ page import="weaver.general.*" %> <%@page import="weaver.conn.RecordSet"%> <%@ page import="com.alibaba.fastjson.JSONObject" %> <%@ page import="java.util.*" %> <%@ page import="com.engine.matfron.entity.OptionVO" %> <%@ page import="com.engine.matfron.entity.SeriesParam" %> <%@ page import="java.util.stream.Collectors" %> <%@ page import="java.text.DecimalFormat" %> <%@ page language="java" contentType="text/html; charset=UTF-8" %> <% JSONObject jsonObject = new JSONObject(); OptionVO optionVO = getPortalEducational(); jsonObject.put("data",optionVO); %> <%=jsonObject.toString() %> <%! public OptionVO getPortalEducational() { DecimalFormat df = new DecimalFormat("#.0"); RecordSet rs = new RecordSet(); List colorList = Arrays.asList("#faf0e6","#7cfc00","#ee8164","#9933fa","#f19c45","#6fcecf","#507ef7","#ao20f0"); LinkedList seriesData = new LinkedList<>(); LinkedList nameSet = new LinkedList<>(); String sql =" select t.xl,d.name,count(1) as sum " + " from uf_jypxjl t\n" + " inner join hrmresource h on h.workcode = t.ygbh\n" + " left join hrmeducationlevel d on t.xl = d.id \n" + " where t.xl is not null \n" + " and h.status in(0,1,2,3)\n" + " and (h.belongto is null or h.belongto = -1 )\n" + " group by t.xl,d.name " + " order by t.xl desc " ; rs.executeQuery(sql); int index = 0; while (rs.next()) { if (index > colorList.size()){ index = 0; } index++; String name = Util.formatMultiLang (Util.null2String(rs.getString("name"))); seriesData.add(SeriesParam.builder().value(Util.getDoubleValue(rs.getString("sum"))).name(name).color(colorList.get(index)).build()); nameSet.add(name); } double percentage = seriesData.stream().mapToDouble(SeriesParam::getValue).sum(); seriesData.forEach(item -> item.setValue(Double.valueOf(df.format((item.getValue() * 100) / percentage)))); // LinkedList legendDataFirst = new LinkedList<>(); // if (nameSet.size() > 2) { // legendDataFirst = treeSetSplitExample(nameSet); // } return OptionVO.builder() .titleText("学历分析") .legendDataFirst(nameSet) // .legendDataTwo(nameSet) .seriesData(seriesData) .build(); } %> <%! /** * 平分legendData * @param nameSet */ private LinkedList treeSetSplitExample(LinkedList nameSet) { int splitSize = nameSet.size() / 2; LinkedList legendDataFirst = nameSet.stream() .collect(Collectors.partitioningBy(e -> nameSet.indexOf(e) < splitSize, Collectors.toCollection(LinkedList::new))) .get(false); nameSet.removeAll(legendDataFirst); return legendDataFirst; } %>