/** * Applies the attributes of this theme to the specified block. * * @param b the block. */ protected void applyToBlock(Block b) { if (b instanceof Title) { applyToTitle((Title) b); } else if (b instanceof LabelBlock) { LabelBlock lb = (LabelBlock) b; lb.setFont(this.regularFont); lb.setPaint(this.legendItemPaint); } }
public String getPieChart(String type , String title , Map hashMap , Date startDate , Date endDate) { CHARTS_PATH = "C://" + type + startDate.getTime()+endDate.getTime()+".jpg"; File file = new File(CHARTS_PATH); if(file.exists()){ file.delete(); } try { DefaultPieDataset dataset = new DefaultPieDataset(); for(Object o : hashMap.keySet()){ dataset.setValue(String.valueOf(o), Integer.parseInt((String) hashMap.get(o))); } JFreeChart chart = ChartFactory.createPieChart3D( title, // 图表标题 dataset, // 绘图数据集 false, // 设定是否显示图例 false, // 设定是否显示图例名称 false); // 设定是否生成链接 chart.setAntiAlias(false); PiePlot pieplot = (PiePlot)chart.getPlot(); pieplot.setLabelFont(new Font("宋体", 0, 15)); pieplot.setNoDataMessage("NO DATA!"); pieplot.setCircular(true); pieplot.setLabelGap(0.02D); pieplot.setBackgroundPaint(new Color(199,237,204)); pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator( "{0} {2}", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); pieplot.setForegroundAlpha(0.6f); LegendTitle legendtitle = new LegendTitle(chart.getPlot()); legendtitle.setWidth(100D); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); blockcontainer.setBorder(new BlockBorder(1.0D, 1.0D, 1.0D, 1.0D)); LabelBlock labelblock = new LabelBlock("Percent:", new Font("宋体", 1, 16)); labelblock.setPadding(5D, 5D, 5D, 5D); blockcontainer.add(labelblock, RectangleEdge.TOP); BlockContainer blockcontainer1 = legendtitle.getItemContainer(); blockcontainer1.setPadding(2D, 10D, 5D, 2D); blockcontainer.add(blockcontainer1); legendtitle.setWrapper(blockcontainer); legendtitle.setPosition(RectangleEdge.RIGHT); legendtitle.setHorizontalAlignment(HorizontalAlignment.LEFT); chart.addSubtitle(legendtitle); chart.setBackgroundPaint(new Color(199,237,204)); TextTitle pcTitle = chart.getTitle(); pcTitle.setFont(new Font("汉真广标", Font.BOLD, 21)); pcTitle.setPaint(Color.RED); ChartUtilities.saveChartAsJPEG(file, chart, CHARTS_WIDTH, CHARTS_HEIGHT); } catch (Exception e) { e.printStackTrace(); } return CHARTS_PATH; }