List of usage examples for org.jfree.chart.title LegendTitle setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:org.jfree.chart.demo.StackedXYBarChartDemo2.java
private static JFreeChart createChart(TableXYDataset tablexydataset) { DateAxis dateaxis = new DateAxis("Date"); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); dateaxis.setLowerMargin(0.01D);//from w ww .j av a 2s . com dateaxis.setUpperMargin(0.01D); NumberAxis numberaxis = new NumberAxis("Count"); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setUpperMargin(0.10000000000000001D); StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.14999999999999999D); stackedxybarrenderer.setDrawBarOutline(false); stackedxybarrenderer.setBaseItemLabelsVisible(true); stackedxybarrenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); stackedxybarrenderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER)); stackedxybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} : {1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0"))); XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer); JFreeChart jfreechart = new JFreeChart("Holes-In-One / Double Eagles", xyplot); jfreechart.removeLegend(); jfreechart.addSubtitle(new TextTitle("PGA Tour, 1983 to 2003")); TextTitle texttitle = new TextTitle( "http://www.golfdigest.com/majors/masters/index.ssf?/majors/masters/gw20040402albatross.html", new Font("Dialog", 0, 8)); jfreechart.addSubtitle(texttitle); jfreechart.setTextAntiAlias(RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); LegendTitle legendtitle = new LegendTitle(xyplot); legendtitle.setBackgroundPaint(Color.white); legendtitle.setFrame(new BlockBorder()); legendtitle.setPosition(RectangleEdge.BOTTOM); jfreechart.addSubtitle(legendtitle); return jfreechart; }
From source file:org.gbif.portal.web.util.ChartUtils.java
/** * Writes out the image using the supplied file name. * // ww w.j a va 2 s . c om * @param legend * @param fileName * @return */ public static String writePieChartImageToTempFile(Map<String, Double> legend, String fileName) { String filePath = System.getProperty(tmpDirSystemProperty) + File.separator + fileName + defaultExtension; File fileToCheck = new File(filePath); if (fileToCheck.exists()) { return fileName + defaultExtension; } final DefaultPieDataset data = new DefaultPieDataset(); Set<String> keys = legend.keySet(); for (String key : keys) { logger.info("Adding key : " + key); data.setValue(key, legend.get(key)); } // create a pie chart... final boolean withLegend = true; final JFreeChart chart = ChartFactory.createPieChart(null, data, withLegend, false, false); PiePlot piePlot = (PiePlot) chart.getPlot(); piePlot.setLabelFont(new Font("Arial", Font.PLAIN, 10)); piePlot.setLabelBackgroundPaint(Color.WHITE); LegendTitle lt = chart.getLegend(); lt.setBackgroundPaint(Color.WHITE); lt.setWidth(300); lt.setBorder(0, 0, 0, 0); lt.setItemFont(new Font("Arial", Font.PLAIN, 11)); chart.setPadding(new RectangleInsets(0, 0, 0, 0)); chart.setBorderVisible(false); chart.setBackgroundImageAlpha(0); chart.setBackgroundPaint(Color.WHITE); chart.setBorderPaint(Color.LIGHT_GRAY); final BufferedImage image = new BufferedImage(300, 250, BufferedImage.TYPE_INT_RGB); KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter(); adapter.setQuality(1); try { adapter.encode(image); } catch (IOException e) { logger.error(e.getMessage(), e); } final Graphics2D g2 = image.createGraphics(); g2.setFont(new Font("Arial", Font.PLAIN, 11)); final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 300, 250); // draw chart.draw(g2, chartArea, null, null); try { FileOutputStream fOut = new FileOutputStream(fileToCheck); ChartUtilities.writeChartAsPNG(fOut, chart, 300, 250); return fileToCheck.getName(); } catch (IOException e) { logger.error(e.getMessage(), e); return null; } }
From source file:org.jfree.chart.demo.XYTitleAnnotationDemo1.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date", "Price Per Unit", xydataset, false, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); LegendTitle legendtitle = new LegendTitle(xyplot); legendtitle.setItemFont(new Font("Dialog", 0, 9)); legendtitle.setBackgroundPaint(new Color(200, 200, 255, 100)); legendtitle.setFrame(new BlockBorder(Color.white)); legendtitle.setPosition(RectangleEdge.BOTTOM); XYTitleAnnotation xytitleannotation = new XYTitleAnnotation(0.97999999999999998D, 0.02D, legendtitle, RectangleAnchor.BOTTOM_RIGHT); xytitleannotation.setMaxWidth(0.47999999999999998D); xyplot.addAnnotation(xytitleannotation); org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer(); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); }//from www. j av a2 s . c o m DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); ValueAxis valueaxis = xyplot.getRangeAxis(); valueaxis.setLowerMargin(0.34999999999999998D); return jfreechart; }
From source file:org.jfree.experimental.chart.demo.XYTitleAnnotationDemo1.java
/** * Creates a chart./*from ww w . j a v a2 s.co m*/ * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data false, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); LegendTitle lt = new LegendTitle(plot); lt.setItemFont(new Font("Dialog", Font.PLAIN, 9)); lt.setBackgroundPaint(new Color(200, 200, 255, 100)); lt.setFrame(new BlockBorder(Color.white)); lt.setPosition(RectangleEdge.BOTTOM); XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, lt, RectangleAnchor.BOTTOM_RIGHT); ta.setMaxWidth(0.48); plot.addAnnotation(ta); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); ValueAxis yAxis = plot.getRangeAxis(); yAxis.setLowerMargin(0.35); return chart; }
From source file:y.graphs.ChartHelperELF.java
private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config, ArrayList<ConfigSerie> series) { final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleMagGraph"), Config.getResource("TitleDate"), Config.getResource("MsgTitleMagGraphYAxis"), dataset, true, // include legend true, // tooltips false // urls );//w w w .j a va2 s . c om chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); LegendTitle lt = new LegendTitle(plot); lt.setItemFont(new Font("Dialog", Font.PLAIN, 12)); lt.setBackgroundPaint(Color.white); lt.setFrame(new BlockBorder(Color.white)); lt.setVerticalAlignment(VerticalAlignment.CENTER); XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt, RectangleAnchor.TOP_RIGHT); ta.setMaxWidth(config.getLegendSize()); plot.addAnnotation(ta); chart.removeLegend(); plot.setBackgroundPaint(config.getColorBackgroundELF()); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); final Stroke lineStroke = new BasicStroke((float) config.getLineWidthELF()); for (int si = 0; si < series.size(); si++) { final ConfigSerie cs = series.get(si); renderer.setSeriesLinesVisible(si, cs.isDrawLine()); final float size = cs.getShapeSize(); renderer.setSeriesShapesVisible(si, size > 0); if (size > 0) renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size)); renderer.setSeriesStroke(si, lineStroke); // renderer.setSeriesOutlineStroke(si, lineStroke); renderer.setSeriesPaint(si, cs.getColor()); } plot.setRenderer(renderer); // x axis final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis(); // rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to rangeAxis.setAutoRange(true); // rangeAxis.setRange(from, to); rangeAxis.setLowerMargin(0.01); rangeAxis.setUpperMargin(0.01); { final Font axisFont = config.getAxisFont(); if (axisFont != null) { rangeAxis.setLabelFont(axisFont); plot.getRangeAxis().setLabelFont(axisFont); } } final String xaxisFmt = config.getAxisFormat(); if (xaxisFmt == null || xaxisFmt.isEmpty()) { double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0); if (diffInDays < 2) rangeAxis.setDateFormatOverride( new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance())); else rangeAxis.setDateFormatOverride( new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance())); } else rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance())); final ValueAxis domain = plot.getRangeAxis(); if (config.getForceYmin() != 0 || config.getForceYmax() != 0) domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()), ElfValue.valueIntToDouble(config.getForceYmax())); // title final Font titleFont = config.getTitleFont(); if (titleFont != null) chart.getTitle().setFont(titleFont); return chart; }
From source file:y.graphs.ChartHelperSRB.java
private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config, ArrayList<ConfigSerie> series) { final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleSrbGraph"), Config.getResource("TitleDate"), Config.getResource("MsgTitleSrbGraphYAxis"), dataset, true, // include legend true, // tooltips false // urls );//w w w.j a va 2 s . c o m chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); LegendTitle lt = new LegendTitle(plot); lt.setItemFont(new Font("Dialog", Font.PLAIN, 12)); lt.setBackgroundPaint(Color.white); lt.setFrame(new BlockBorder(Color.white)); lt.setVerticalAlignment(VerticalAlignment.CENTER); XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt, RectangleAnchor.TOP_RIGHT); ta.setMaxWidth(config.getLegendSize()); plot.addAnnotation(ta); chart.removeLegend(); plot.setBackgroundPaint(config.getColorBackgroundSRB()); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); final Stroke lineStroke = new BasicStroke((float) config.getLineWidthSRB()); for (int si = 0; si < series.size(); si++) { final ConfigSerie cs = series.get(si); renderer.setSeriesLinesVisible(si, cs.isDrawLine()); final float size = cs.getShapeSize(); renderer.setSeriesShapesVisible(si, size > 0); if (size > 0) renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size)); renderer.setSeriesStroke(si, lineStroke); // renderer.setSeriesOutlineStroke(si, lineStroke); renderer.setSeriesPaint(si, cs.getColor()); } plot.setRenderer(renderer); // x axis final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis(); // rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to rangeAxis.setAutoRange(true); // rangeAxis.setRange(from, to); rangeAxis.setLowerMargin(0.01); rangeAxis.setUpperMargin(0.01); { final Font axisFont = config.getAxisFont(); if (axisFont != null) { rangeAxis.setLabelFont(axisFont); plot.getRangeAxis().setLabelFont(axisFont); } } final String xaxisFmt = config.getAxisFormat(); if (xaxisFmt == null || xaxisFmt.isEmpty()) { double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0); if (diffInDays < 2) rangeAxis.setDateFormatOverride( new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance())); else rangeAxis.setDateFormatOverride( new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance())); } else rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance())); final ValueAxis domain = plot.getRangeAxis(); if (config.getForceYmin() != 0 || config.getForceYmax() != 0) domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()), ElfValue.valueIntToDouble(config.getForceYmax())); // title final Font titleFont = config.getTitleFont(); if (titleFont != null) chart.getTitle().setFont(titleFont); return chart; }
From source file:uk.ac.lkl.cram.ui.chart.TLALearningTypeChartFactory.java
private static JFreeChart createChart(PieDataset dataset) { //Create a pie chart from the chart factory with no title, a legend and no tooltips JFreeChart chart = ChartFactory.createPieChart(null, dataset, true, false, false); //Set the background colour of the chart Paint backgroundPaint = Color.white; chart.setBackgroundPaint(backgroundPaint); //Get the plot from the chart PiePlot plot = (PiePlot) chart.getPlot(); //Set the background colour of the plot to be the same as the chart plot.setBackgroundPaint(backgroundPaint); //Remove shadows from the plot plot.setShadowXOffset(0);/*from w ww.j av a2 s . c o m*/ plot.setShadowYOffset(0); //Remove the outline from the plot plot.setOutlineVisible(false); //Remove the labels from the plot plot.setLabelGenerator(null); //Set the colours for the segments plot.setSectionPaint(LearningTypeChartMaker.ACQUISITION, LearningTypeChartMaker.ACQUISITION_COLOR); plot.setSectionPaint(LearningTypeChartMaker.COLLABORATION, LearningTypeChartMaker.COLLABORATION_COLOR); plot.setSectionPaint(LearningTypeChartMaker.DISCUSSION, LearningTypeChartMaker.DISCUSSION_COLOR); plot.setSectionPaint(LearningTypeChartMaker.INQUIRY, LearningTypeChartMaker.INQUIRY_COLOR); plot.setSectionPaint(LearningTypeChartMaker.PRACTICE, LearningTypeChartMaker.PRACTICE_COLOR); plot.setSectionPaint(LearningTypeChartMaker.PRODUCTION, LearningTypeChartMaker.PRODUCTION_COLOR); //Get the legend from the chart LegendTitle legend = chart.getLegend(); //Set the font of the legend to be the same as the platform UI legend.setItemFont(UIManager.getFont("Label.font")); //Set the background colour of the legend to be the same as the chart legend.setBackgroundPaint(backgroundPaint); //Remove the border from the legend legend.setFrame(BlockBorder.NONE); //Locate the legend to the right of the plot legend.setPosition(RectangleEdge.RIGHT); return chart; }
From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java
public static void customizeLegend(LegendTitle legend, ChartParams params) { if (params.get(ChartParams.LEGEND_BACKGROUND_COLOR) != null) { legend.setBackgroundPaint(params.getColor(ChartParams.LEGEND_BACKGROUND_COLOR)); }//www. j av a 2 s. c o m if (params.get(ChartParams.LEGEND_ITEM_FONT) != null) { legend.setItemFont(params.getFont(ChartParams.LEGEND_ITEM_FONT)); } if (params.get(ChartParams.LEGEND_ITEM_LABEL_PADDING) != null) { legend.setItemLabelPadding(params.getRectangleInsets(ChartParams.LEGEND_ITEM_LABEL_PADDING)); } if (params.get(ChartParams.LEGEND_ITEM_GRAPHIC_ANCHOR) != null) { legend.setLegendItemGraphicAnchor(params.getRectangleAnchor(ChartParams.LEGEND_ITEM_GRAPHIC_ANCHOR)); } if (params.get(ChartParams.LEGEND_ITEM_GRAPHIC_EDGE) != null) { legend.setLegendItemGraphicEdge(params.getRectangleEdge(ChartParams.LEGEND_ITEM_GRAPHIC_EDGE)); } if (params.get(ChartParams.LEGEND_ITEM_GRAPHIC_LOCATION) != null) { legend.setLegendItemGraphicAnchor(params.getRectangleAnchor(ChartParams.LEGEND_ITEM_GRAPHIC_LOCATION)); } if (params.get(ChartParams.LEGEND_ITEM_GRAPHIC_PADDING) != null) { legend.setLegendItemGraphicPadding(params.getRectangleInsets(ChartParams.LEGEND_ITEM_GRAPHIC_PADDING)); } }
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * Sets the colours and gradients to be used when painting the given JFreeChart. * //from www. ja v a2 s . c om * @param chart * The JFreeChart to make nice. */ public static void makeChartNice(JFreeChart chart) { Plot plot = chart.getPlot(); chart.setBackgroundPaint(null); chart.setBorderStroke(new BasicStroke(1f)); chart.setBorderPaint(new Color(0xDDDDDD)); chart.setBorderVisible(true); // TODO Should we add an option for subtitles, this is where it would go. // TextTitle subTitle = new TextTitle("What's up doc?", // new Font("SansSerif", Font.BOLD, 8)); // chart.addSubtitle(subTitle); // overall plot plot.setOutlinePaint(null); plot.setInsets(new RectangleInsets(0, 5, 0, 5)); // also the overall chart panel plot.setBackgroundPaint(null); plot.setDrawingSupplier(new WabitDrawingSupplier()); // legend LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setBorder(0, 0, 0, 0); legend.setBackgroundPaint(null); legend.setPadding(2, 2, 2, 2); } if (plot instanceof CategoryPlot) { CategoryPlot cplot = (CategoryPlot) plot; CategoryItemRenderer renderer = cplot.getRenderer(); if (renderer instanceof BarRenderer) { BarRenderer brenderer = (BarRenderer) renderer; brenderer.setBarPainter(new StandardBarPainter()); brenderer.setDrawBarOutline(false); brenderer.setShadowVisible(false); brenderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); } else if (renderer instanceof LineAndShapeRenderer) { // it's all taken care of by WabitDrawingSupplier } else { logger.warn("I don't know how to make " + renderer + " pretty. Leaving ugly."); } cplot.setRangeGridlinePaint(Color.BLACK); cplot.setRangeGridlineStroke(GRIDLINE_STROKE); // axes for (int i = 0; i < cplot.getDomainAxisCount(); i++) { CategoryAxis axis = cplot.getDomainAxis(i); axis.setAxisLineVisible(false); } for (int i = 0; i < cplot.getRangeAxisCount(); i++) { ValueAxis axis = cplot.getRangeAxis(i); axis.setAxisLineVisible(false); } } if (plot instanceof MultiplePiePlot) { MultiplePiePlot mpplot = (MultiplePiePlot) plot; JFreeChart pchart = mpplot.getPieChart(); PiePlot3DGradient pplot = (PiePlot3DGradient) pchart.getPlot(); pplot.setBackgroundPaint(null); pplot.setOutlinePaint(null); pplot.setFaceGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); pplot.setSideGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); CategoryDataset data = mpplot.getDataset(); Color[][] colours = WabitDrawingSupplier.SERIES_COLOURS; //Set all colours for (int i = 0; i < colours.length; i++) { if (data.getColumnCount() >= i + 1) { pplot.setSectionOutlinePaint(data.getColumnKey(i), null); GradientPaint gradient = new GradientPaint(0, 0f, colours[i][0], 100, 0f, colours[i][1]); pplot.setSectionPaint(data.getColumnKey(i), gradient); gradient = new GradientPaint(0, 0f, colours[i][1], 100, 0f, colours[i][0]); pplot.setSidePaint(data.getColumnKey(i), gradient); } } } // Tweak the title font size chart.getTitle().setFont(chart.getTitle().getFont().deriveFont(14f)); chart.getTitle().setPadding(5, 0, 5, 0); chart.setAntiAlias(true); // shrink padding chart.setPadding(new RectangleInsets(0, 0, 0, 0)); }
From source file:com.hmsinc.epicenter.webapp.chart.ChartService.java
/** * @param chart//from w w w .j a v a 2 s. co m * @return */ private static void configureTitleAndLegend(final JFreeChart chart, final AbstractChart adapter) { final TextTitle title = chart.getTitle(); if (title != null) { title.setFont(new Font("Arial", Font.BOLD, 12)); // title.setBackgroundPaint(Color.CYAN); title.setTextAlignment(HorizontalAlignment.LEFT); title.setHorizontalAlignment(HorizontalAlignment.CENTER); title.setMargin(0, 4, 5, 6); } if (chart.getLegend() != null) { chart.removeLegend(); final LegendTitle legend = new LegendTitle(chart.getPlot(), new SNColumnArrangement(0, 0), new ColumnArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 0, 0)); legend.setItemFont(LEGEND_FONT); legend.setPosition(RectangleEdge.BOTTOM); legend.setHorizontalAlignment(HorizontalAlignment.CENTER); legend.setBackgroundPaint(Color.WHITE); legend.setFrame(new LineBorder()); legend.setMargin(0, 4, 5, 6); chart.addLegend(legend); // Now we'll try to remove any duplicate items from the legend.. final Map<String, Integer> keys = new HashMap<String, Integer>(); final LegendItemCollection items = new LegendItemCollection(); for (LegendItemSource source : legend.getSources()) { for (int i = 0; i < source.getLegendItems().getItemCount(); i++) { final LegendItem item = source.getLegendItems().get(i); if (!keys.containsKey(item.getLabel())) { keys.put(item.getLabel(), i); items.add(item); } } } legend.setSources(new LegendItemSource[] { new LegendItemSource() { /* * (non-Javadoc) * * @see org.jfree.chart.LegendItemSource#getLegendItems() */ public LegendItemCollection getLegendItems() { return items; } } }); } }