
使用JFreeChart来创建基于web的带交互功能的PIE图表(二)(2) |
if (request.getParameter("legDire") != null) { try { iLegDire = Integer.parseInt(request.getParameter("legDire")); } catch (NumberFormatException ex2) { } } boolean bShowPercent = false; if (request.getParameter("showPercent") != null && request.getParameter("showPercent").equals("true")) { bShowPercent = true; } int iLabelHeight = 10; if (request.getParameter("labelHeight") != null) { try { iLabelHeight = Integer.parseInt(request.getParameter("labelHeight")); } catch (NumberFormatException ex2) { } } int elemCount = 100; if (request.getParameter("elemCount") != null) { try { elemCount = Integer.parseInt(request.getParameter("elemCount")); } catch (NumberFormatException ex3) { } } HttpSession session = request.getSession(); Object formInSession = session.getAttribute(formName); String propName = request.getParameter("property"); String methodName1 = getGetMethodName(request.getParameter("field1")); String methodName2 = getGetMethodName(request.getParameter("field2")); Method m = formInSession.getClass().getMethod(getGetMethodName(propName), new Class[0]); Collection coll = (Collection) m.invoke(formInSession, null); DefaultPieDataset data = getDataSet(coll, methodName1, methodName2, elemCount); JFreeChart chart = ChartFactory.createPieChart3D(title, data, bLegend, false, false ); int width = 400; int height = 300; try { width = Integer.parseInt(request.getParameter("width")); height = Integer.parseInt(request.getParameter("height")); } catch (NumberFormatException ex) { } PiePlot pie = (PiePlot) chart.getPlot(); //pie.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS); //pie.setSectionLabelType(PiePlot.VALUE_AND_PERCENT_LABELS); pie.setInteriorGap(0.15); if (!bShowLabel) { pie.setLabelGenerator(null); } String numFlag = ""; if (request.getParameter("numFlag") != null) { numFlag = request.getParameter("numFlag"); } if (bShowPercent) { pie.setLabelGenerator(new StandardPieItemLabelGenerator( "{0}=" + numFlag + "{1}({2})", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance() )); } else { pie.setLabelGenerator(new StandardPieItemLabelGenerator( "{0}=" + numFlag + "{1}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance() )); } pie.setInteriorGap(0.23); pie.setLabelFont(new Font("dialog", Font.TRUETYPE_FONT, iLabelHeight)); pie.setMaximumLabelWidth(0.3); //pie.setLabelGap(0.0); chart.getLegend().setAnchor(iLegDire); chart.setBackgroundPaint(java.awt.Color.white); if (request.getParameter("fieldColor") != null) { String mapName = request.getParameter("mapName"); //response.setDateHeader("Expires", System.currentTimeMillis()); } private void setPieSecColor(Collection coll, PiePlot pie, String colorMethodName) { private String getGetMethodName(String name) { private static DefaultPieDataset getDataSet(Collection coll, String methodName1, String methodName2, int elemCount) throws } |