private static String[] colors = new String[] { "#ff6600", "#339999", "#ff6633", "#999900", "#ffff33", "#333366", "#993333", "#99cccc", "#cc9900", "#999999", "#999933", "#006600", "#003366", "#99cc66" }; /* * 构造饼图 */ private Chart drawPieChar(List<BigDecimal> datas, String titletext, List<SysCode> syscodes) { Chart chart = new Chart(); Title title = new Title(); title.setText(titletext); title.setStyle("{colour:#DDDDDD;font-size: 15px;}"); Pie pie = new Pie(); pie.setAlpha(0.6); pie.setAnimate(true); pie.setBorder(6.0); pie.setTip("#label# $#val#<br>#percent#"); pie.setValues(contructValue(syscodes, datas)); pie.setColours(this.contructPieColor(datas)); Legend legend = new Legend(); legend.setBg_colour("#fefefe"); legend.setPosition("right"); chart.setLegend(legend); chart.setPie(pie); chart.setTitle(title); chart.setBg_colour("#FFFFFF"); return chart; } private List<PieValue> contructValue(List<SysCode> syscodes, List<BigDecimal> datas) { BigDecimal sum = new BigDecimal(0); BigDecimal percnet = new BigDecimal(0); for (BigDecimal s : datas) { sum = sum.add(s); } DecimalFormat format = new DecimalFormat("##.##%"); List<PieValue> list = new ArrayList<PieValue>(); for (int i = 0; i < syscodes.size(); i++) { PieValue pieValue = new PieValue(); String label = syscodes.get(i).getLocaleName(); /* * if(label!=null){ if(label.length()>13){ label = * label.substring(0, 13); } } */ if (sum.compareTo(new BigDecimal(0))!=0) { percnet = datas.get(i).divide(sum, 4, BigDecimal.ROUND_HALF_UP); } pieValue.setText(label + "(" + format.format(percnet.doubleValue()) + ")"); // pieValue.setLabel(label); // pieValue.setTip("#percent#"); pieValue.setValue(datas.get(i)); list.add(pieValue); } return list; } /* * 颜色匹配 */ private String[] contructPieColor(List<BigDecimal> datas) { List<String> piecolors = new ArrayList<String>(); int j = 0; for (int i = 0; i < datas.size(); i++) { j = i; if (j > colors.length) { j = 0; } piecolors.add(colors[i]); } String[] colors = {}; colors = piecolors.toArray(colors); return colors; }