List of usage examples for org.jfree.chart.title LegendTitle setPadding
public void setPadding(RectangleInsets padding)
From source file:unalcol.termites.boxplots.ECALMessages.java
/** * Creates a new demo.//from ww w . j av a 2 s . c o m * * @param title the frame title. * @param pf */ public ECALMessages(final String title, ArrayList<Double> pf) { super(title); final CategoryAxis xAxis = new CategoryAxis(""); //final NumberAxis yAxis = new NumberAxis("Messages Sent"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf, renderer); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 13); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Messages Sent " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); LegendTitle legend = chart.getLegend(); legend.setPadding(new RectangleInsets(UnitType.RELATIVE, 0, 0.1, 0, 0)); FileOutputStream output; try { output = new FileOutputStream("messagesECAL" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 670, 250, null); } catch (FileNotFoundException ex) { Logger.getLogger(ECALMessages.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ECALMessages.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:unalcol.termites.boxplots.MessagesSent2.java
/** * Creates a new demo./*from w ww. j a v a 2 s.c o m*/ * * @param title the frame title. * @param pf */ public MessagesSent2(final String title, ArrayList<Double> pf) { super(title); final CategoryAxis xAxis = new CategoryAxis(""); //final NumberAxis yAxis = new NumberAxis("Messages Sent"); final NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); final BoxAndWhiskerCategoryDataset dataset = createSampleDataset(pf, renderer); renderer.setFillBox(false); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); Font font = new Font("Dialog", Font.PLAIN, 13); xAxis.setTickLabelFont(font); yAxis.setTickLabelFont(font); yAxis.setLabelFont(font); final JFreeChart chart = new JFreeChart("Messages Sent " + getTitle(pf), new Font("SansSerif", Font.BOLD, 18), plot, true); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(650, 370)); setContentPane(chartPanel); TextTitle legendText = null; if (pf.size() == 1) { legendText = new TextTitle("Population Size"); } else { legendText = new TextTitle("Population Size - Probability of Failure"); } legendText.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legendText); LegendTitle legend = chart.getLegend(); legend.setPadding(new RectangleInsets(UnitType.RELATIVE, 0, 0.1, 0, 0)); FileOutputStream output; try { output = new FileOutputStream("messagesnumber2" + pf + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 670, 250, null); } catch (FileNotFoundException ex) { Logger.getLogger(MessagesSent2.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MessagesSent2.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.logisticPlanning.utils.graphics.chart.impl.jfree._JFCLineChart2D.java
/** * paint a legend// w w w . j a va 2 s.com * * @param legend * the legend * @param graphics * the graphics * @param bounds * the bounds */ private static final void __paintLegend(final LegendTitle legend, final Graphics2D graphics, final Rectangle2D bounds) { final Rectangle2D titleArea; final BlockParams p; final double ww, hh; final RectangleConstraint constraint; final Size2D size; p = new BlockParams(); p.setGenerateEntities(false); ww = bounds.getWidth(); if (ww <= 0.0d) { return; } hh = bounds.getHeight(); if (hh <= 0.0d) { return; } constraint = new RectangleConstraint(ww, new Range(0.0, ww), LengthConstraintType.RANGE, hh, new Range(0.0, hh), LengthConstraintType.RANGE); size = legend.arrange(graphics, constraint); titleArea = _JFCLineChart2D.__createAlignedRectangle2D(size, bounds, legend.getHorizontalAlignment(), VerticalAlignment.TOP); legend.setMargin(_JFCLineChart2D.LEGEND_MARGIN); legend.setPadding(_JFCLineChart2D.CHART_INSETS); legend.draw(graphics, titleArea, p); }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
protected void setChartLegend(JFreeChart jfreeChart) { //The legend visibility is already taken into account in the jfreeChart object's constructor LegendTitle legend = jfreeChart.getLegend(); if (legend != null) { LegendSettings legendSettings = getLegendSettings(); JRBaseFont font = new JRBaseFont(); JRFontUtil.copyNonNullOwnProperties(legendSettings.getFont(), font); JRFontUtil.copyNonNullOwnProperties(getChart().getLegendFont(), font); font = new JRBaseFont(getChart(), font); legend.setItemFont(JRFontUtil.getAwtFont(font, getLocale())); Paint forePaint = getChart().getOwnLegendColor(); if (forePaint == null && legendSettings.getForegroundPaint() != null) { forePaint = legendSettings.getForegroundPaint().getPaint(); }/*from www .j a v a 2s. co m*/ if (forePaint == null) { forePaint = getChart().getLegendColor(); } if (forePaint != null) legend.setItemPaint(forePaint); Paint backPaint = getChart().getOwnLegendBackgroundColor(); if (backPaint == null && legendSettings.getBackgroundPaint() != null) { backPaint = legendSettings.getBackgroundPaint().getPaint(); } if (backPaint == null) { backPaint = getChart().getLegendBackgroundColor(); } if (backPaint != null) legend.setBackgroundPaint(backPaint); BlockFrame blockFrame = legendSettings.getBlockFrame(); if (blockFrame != null) legend.setFrame(blockFrame); HorizontalAlignment hAlign = legendSettings.getHorizontalAlignment(); if (hAlign != null) legend.setHorizontalAlignment(hAlign); VerticalAlignment vAlign = legendSettings.getVerticalAlignment(); if (vAlign != null) legend.setVerticalAlignment(vAlign); RectangleInsets padding = legendSettings.getPadding(); if (padding != null) legend.setPadding(padding); legend.setPosition(getEdge(getChart().getLegendPositionValue(), getEdge(legendSettings.getPositionValue(), RectangleEdge.BOTTOM))); } }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
protected void setChartLegend(JFreeChart jfreeChart) { //The legend visibility is already taken into account in the jfreeChart object's constructor LegendTitle legend = jfreeChart.getLegend(); if (legend != null) { LegendSettings legendSettings = getLegendSettings(); JRBaseFont font = new JRBaseFont(); FontUtil.copyNonNullOwnProperties(legendSettings.getFont(), font); FontUtil.copyNonNullOwnProperties(getChart().getLegendFont(), font); font = new JRBaseFont(getChart(), font); legend.setItemFont(getFontUtil().getAwtFont(font, getLocale())); Paint forePaint = getChart().getOwnLegendColor(); if (forePaint == null && legendSettings.getForegroundPaint() != null) { forePaint = legendSettings.getForegroundPaint().getPaint(); }//from w w w . ja v a 2 s . c o m if (forePaint == null) { forePaint = getChart().getLegendColor(); } if (forePaint != null) legend.setItemPaint(forePaint); Paint backPaint = getChart().getOwnLegendBackgroundColor(); if (backPaint == null && legendSettings.getBackgroundPaint() != null) { backPaint = legendSettings.getBackgroundPaint().getPaint(); } if (backPaint == null) { backPaint = getChart().getLegendBackgroundColor(); } if (backPaint != null) legend.setBackgroundPaint(backPaint); BlockFrame blockFrame = legendSettings.getBlockFrame(); if (blockFrame != null) legend.setFrame(blockFrame); HorizontalAlignment hAlign = legendSettings.getHorizontalAlignment(); if (hAlign != null) legend.setHorizontalAlignment(hAlign); VerticalAlignment vAlign = legendSettings.getVerticalAlignment(); if (vAlign != null) legend.setVerticalAlignment(vAlign); RectangleInsets padding = legendSettings.getPadding(); if (padding != null) legend.setPadding(padding); legend.setPosition(getEdge(getChart().getLegendPositionValue(), getEdge(legendSettings.getPositionValue(), RectangleEdge.BOTTOM))); } }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
protected void setChartLegend(JFreeChart jfreeChart, Integer baseFontSize) { //The legend visibility is already taken into account in the jfreeChart object's constructor LegendTitle legend = jfreeChart.getLegend(); if (legend != null) { Font themeLegendFont = getFont( (JRFont) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FONT), getChart().getLegendFont(), baseFontSize); legend.setItemFont(themeLegendFont); Color legendForecolor = getChart().getOwnLegendColor() != null ? getChart().getOwnLegendColor() : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FORECOLOR) != null ? (Color) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FORECOLOR) : getChart().getLegendColor()); if (legendForecolor != null) legend.setItemPaint(legendForecolor); Color legendBackcolor = getChart().getOwnLegendBackgroundColor() != null ? getChart().getOwnLegendBackgroundColor() : (getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_BACKCOLOR) != null ? (Color) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_BACKCOLOR) : getChart().getLegendBackgroundColor()); if (legendBackcolor != null) legend.setBackgroundPaint(legendBackcolor); BlockFrame frame = (BlockFrame) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FRAME); if (frame != null) legend.setFrame(frame);//from w ww. j a v a2s .co m HorizontalAlignment defaultLegendHAlignment = (HorizontalAlignment) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.LEGEND_HORIZONTAL_ALIGNMENT); if (defaultLegendHAlignment != null) legend.setHorizontalAlignment(defaultLegendHAlignment); VerticalAlignment defaultLegendVAlignment = (VerticalAlignment) getDefaultValue( defaultChartPropertiesMap, ChartThemesConstants.LEGEND_VERTICAL_ALIGNMENT); if (defaultLegendVAlignment != null) legend.setVerticalAlignment(defaultLegendVAlignment); RectangleInsets defaultLegendPadding = (RectangleInsets) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_PADDING); RectangleInsets legendPadding = legend.getPadding() != null ? legend.getPadding() : defaultLegendPadding; if (legendPadding != null) legend.setPadding(legendPadding); RectangleEdge defaultLegendPosition = (RectangleEdge) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_POSITION); if (getEdge(getChart().getLegendPositionValue(), defaultLegendPosition) != null) legend.setPosition(getEdge(getChart().getLegendPositionValue(), defaultLegendPosition)); } }