List of usage examples for org.jfree.chart.title LegendTitle setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:userinterface.graph.Histogram.java
/** * Update the settings of the graph if the settings changed *///w ww .j av a 2 s.co m public void updateGraph() { /* Update title if necessary. */ if (!this.chart.getTitle().equals(graphTitle)) { this.chart.setTitle(graphTitle.getStringValue()); } /* Update title font if necessary. */ if (!titleFont.getFontColorValue().f.equals(this.chart.getTitle().getFont())) { this.chart.getTitle().setFont(titleFont.getFontColorValue().f); } /* Update title colour if necessary. */ if (!titleFont.getFontColorValue().c.equals(this.chart.getTitle().getPaint())) { this.chart.getTitle().setPaint(titleFont.getFontColorValue().c); } if (legendVisible.getBooleanValue() != (this.chart.getLegend() != null)) { if (!legendVisible.getBooleanValue()) { this.chart.removeLegend(); } else { LegendTitle legend = new LegendTitle(plot.getRenderer()); legend.setBackgroundPaint(Color.white); legend.setBorder(1, 1, 1, 1); this.chart.addLegend(legend); } } if (this.chart.getLegend() != null) { LegendTitle legend = this.chart.getLegend(); /* Put legend on the left if appropriate. */ if ((legendPosition.getCurrentIndex() == Graph.LEFT) && !legend.getPosition().equals(RectangleEdge.LEFT)) { legend.setPosition(RectangleEdge.LEFT); } /* Put legend on the right if appropriate. */ if ((legendPosition.getCurrentIndex() == Graph.RIGHT) && !legend.getPosition().equals(RectangleEdge.RIGHT)) { legend.setPosition(RectangleEdge.RIGHT); } /* Put legend on the top if appropriate. */ if ((legendPosition.getCurrentIndex() == Graph.TOP) && !legend.getPosition().equals(RectangleEdge.TOP)) { legend.setPosition(RectangleEdge.TOP); } /* Put legend on the bottom if appropriate. */ if ((legendPosition.getCurrentIndex() == Graph.BOTTOM) && !legend.getPosition().equals(RectangleEdge.BOTTOM)) { legend.setPosition(RectangleEdge.BOTTOM); } /* Set legend font. */ if (!legend.getItemFont().equals(legendFont.getFontColorValue().f)) { legend.setItemFont(legendFont.getFontColorValue().f); } /* Set legend font colour. */ if (!legend.getItemPaint().equals(legendFont.getFontColorValue().c)) { legend.setItemPaint(legendFont.getFontColorValue().c); } } super.repaint(); doEnables(); }
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
protected void setLegendStyles(JFreeChart chart, UIChart comp) { Boolean showLegend = comp.getShowLegend(); if (showLegend != null && !showLegend) { return;//from w w w . j a v a 2 s . co m } UILegend legendcomp = comp.getLegend(); if (legendcomp == null) { if (showLegend != null && showLegend) { // Create default legend LegendTitle legend = new LegendTitle(chart.getPlot()); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setFrame(new LineBorder()); legend.setBackgroundPaint(Color.white); legend.setPosition(RectangleEdge.BOTTOM); chart.addSubtitle(legend); } } else { chart.addSubtitle(createLegend(chart, legendcomp)); } }
From source file:userinterface.graph.Graph.java
private void updateGraph() { /* Update title if necessary. */ if (!this.chart.getTitle().equals(graphTitle)) { this.chart.setTitle(graphTitle.getStringValue()); }/*from www. ja v a 2 s . c om*/ /* Update title font if necessary. */ if (!titleFont.getFontColorValue().f.equals(this.chart.getTitle().getFont())) { this.chart.getTitle().setFont(titleFont.getFontColorValue().f); } /* Update title colour if necessary. */ if (!titleFont.getFontColorValue().c.equals(this.chart.getTitle().getPaint())) { this.chart.getTitle().setPaint(titleFont.getFontColorValue().c); } if (legendVisible.getBooleanValue() != (this.chart.getLegend() != null)) { if (!legendVisible.getBooleanValue()) { this.chart.removeLegend(); } else { LegendTitle legend = new LegendTitle(plot.getRenderer()); legend.setBackgroundPaint(Color.white); legend.setBorder(1, 1, 1, 1); this.chart.addLegend(legend); } } if (this.chart.getLegend() != null) { LegendTitle legend = this.chart.getLegend(); /* Put legend on the left if appropriate. */ if ((legendPosition.getCurrentIndex() == LEFT) && !legend.getPosition().equals(RectangleEdge.LEFT)) { legend.setPosition(RectangleEdge.LEFT); } /* Put legend on the right if appropriate. */ if ((legendPosition.getCurrentIndex() == RIGHT) && !legend.getPosition().equals(RectangleEdge.RIGHT)) { legend.setPosition(RectangleEdge.RIGHT); } /* Put legend on the top if appropriate. */ if ((legendPosition.getCurrentIndex() == TOP) && !legend.getPosition().equals(RectangleEdge.TOP)) { legend.setPosition(RectangleEdge.TOP); } /* Put legend on the bottom if appropriate. */ if ((legendPosition.getCurrentIndex() == BOTTOM) && !legend.getPosition().equals(RectangleEdge.BOTTOM)) { legend.setPosition(RectangleEdge.BOTTOM); } /* Set legend font. */ if (!legend.getItemFont().equals(legendFont.getFontColorValue().f)) { legend.setItemFont(legendFont.getFontColorValue().f); } /* Set legend font colour. */ if (!legend.getItemPaint().equals(legendFont.getFontColorValue().c)) { legend.setItemPaint(legendFont.getFontColorValue().c); } } super.repaint(); doEnables(); }
From source file:org.pentaho.plugin.jfreereport.reportcharts.AbstractChartExpression.java
protected void configureChart(final JFreeChart chart) { // Misc Properties final TextTitle chartTitle = chart.getTitle(); if (chartTitle != null) { final Font titleFont = Font.decode(getTitleFont()); chartTitle.setFont(titleFont);/*from w w w . j av a 2 s. c o m*/ } if (isAntiAlias() == false) { chart.setAntiAlias(false); } chart.setBorderVisible(isShowBorder()); final Color backgroundColor = parseColorFromString(getBackgroundColor()); if (backgroundColor != null) { chart.setBackgroundPaint(backgroundColor); } if (plotBackgroundColor != null) { chart.getPlot().setBackgroundPaint(plotBackgroundColor); } chart.getPlot().setBackgroundAlpha(plotBackgroundAlpha); chart.getPlot().setForegroundAlpha(plotForegroundAlpha); final Color borderCol = parseColorFromString(getBorderColor()); if (borderCol != null) { chart.setBorderPaint(borderCol); } //remove legend if showLegend = false if (!isShowLegend()) { chart.removeLegend(); } else { //if true format legend final LegendTitle chLegend = chart.getLegend(); if (chLegend != null) { final RectangleEdge loc = translateEdge(legendLocation.toLowerCase()); if (loc != null) { chLegend.setPosition(loc); } if (getLegendFont() != null) { chLegend.setItemFont(Font.decode(getLegendFont())); } if (!isDrawLegendBorder()) { chLegend.setBorder(BlockBorder.NONE); } if (legendBackgroundColor != null) { chLegend.setBackgroundPaint(legendBackgroundColor); } if (legendTextColor != null) { chLegend.setItemPaint(legendTextColor); } } } final Plot plot = chart.getPlot(); plot.setNoDataMessageFont(Font.decode(getLabelFont())); final String message = getNoDataMessage(); if (message != null) { plot.setNoDataMessage(message); } plot.setOutlineVisible(isChartSectionOutline()); if (backgroundImage != null) { if (plotImageCache != null) { plot.setBackgroundImage(plotImageCache); } else { final ExpressionRuntime expressionRuntime = getRuntime(); final ProcessingContext context = expressionRuntime.getProcessingContext(); final ResourceKey contentBase = context.getContentBase(); final ResourceManager manager = context.getResourceManager(); try { final ResourceKey key = createKeyFromString(manager, contentBase, backgroundImage); final Resource resource = manager.create(key, null, Image.class); final Image image = (Image) resource.getResource(); plot.setBackgroundImage(image); plotImageCache = image; } catch (Exception e) { logger.error("ABSTRACTCHARTEXPRESSION.ERROR_0007_ERROR_RETRIEVING_PLOT_IMAGE", e); //$NON-NLS-1$ throw new IllegalStateException("Failed to process chart"); } } } }
From source file:lucee.runtime.tag.Chart.java
private void setLegend(JFreeChart chart, Plot plot, Font font) { if (!showlegend) return;// w w w. j a va 2s .c o m Color bg = backgroundcolor == null ? databackgroundcolor : backgroundcolor; if (font == null) font = getFont(); LegendTitle legend = legendMultiLine ? new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement()) : new LegendTitle(plot); legend.setBackgroundPaint(bg); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setFrame(new LineBorder()); legend.setPosition(RectangleEdge.BOTTOM); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setWidth(chartwidth - 20);// geht nicht legend.setItemFont(font); legend.setItemPaint(foregroundcolor); //RectangleInsets labelPadding; legend.setItemLabelPadding(new RectangleInsets(2, 2, 2, 2)); legend.setBorder(0, 0, 0, 0); legend.setLegendItemGraphicLocation(RectangleAnchor.TOP_LEFT); legend.setLegendItemGraphicPadding(new RectangleInsets(8, 10, 0, 0)); chart.addLegend(legend); }
From source file:org.operamasks.faces.render.graph.ChartRenderer.java
private LegendTitle createLegend(JFreeChart chart, UILegend legendcomp) { LegendTitle legend = new LegendTitle(chart.getPlot()); PositionType position = legendcomp.getPosition(); if (position == null) { legend.setPosition(RectangleEdge.BOTTOM); } else {// w w w .j a va 2 s . co m setTitlePosition(legend, position); } Double tm = legendcomp.getTopMargin(); Double lm = legendcomp.getLeftMargin(); Double bm = legendcomp.getBottomMargin(); Double rm = legendcomp.getRightMargin(); if (tm == null) tm = 1.0; if (lm == null) lm = 1.0; if (bm == null) bm = 1.0; if (rm == null) rm = 1.0; legend.setMargin(new RectangleInsets(tm, lm, bm, rm)); Paint bgcolor = legendcomp.getBackgroundColor(); if (bgcolor != null) { legend.setBackgroundPaint(bgcolor); } Float borderWidth = legendcomp.getBorderWidth(); Paint borderColor = legendcomp.getBorderColor(); if (borderWidth != null || borderColor != null) { if (borderWidth == null) borderWidth = 1.0f; if (borderColor == null) borderColor = Color.black; LineBorder border = new LineBorder(borderColor, new BasicStroke(borderWidth), new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setFrame(border); } Font itemFont = legendcomp.getItemFont(); Paint itemColor = legendcomp.getItemColor(); if (itemFont != null) legend.setItemFont(itemFont); if (itemColor != null) legend.setItemPaint(itemColor); return legend; }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * */// w w w . j a v a2s. com protected void configureChart(JFreeChart jfreeChart) throws JRException { if (getChart().getModeValue() == ModeEnum.OPAQUE) { jfreeChart.setBackgroundPaint(getChart().getBackcolor()); } else { jfreeChart.setBackgroundPaint(null); } RectangleEdge titleEdge = getEdge(getChart().getTitlePositionValue(), RectangleEdge.TOP); if (jfreeChart.getTitle() != null) { TextTitle title = jfreeChart.getTitle(); title.setPaint(getChart().getTitleColor()); title.setFont(fontUtil.getAwtFont(getFont(getChart().getTitleFont()), getLocale())); title.setPosition(titleEdge); } String subtitleText = evaluateTextExpression(getChart().getSubtitleExpression()); if (subtitleText != null) { TextTitle subtitle = new TextTitle(subtitleText); subtitle.setPaint(getChart().getSubtitleColor()); subtitle.setFont(fontUtil.getAwtFont(getFont(getChart().getSubtitleFont()), getLocale())); subtitle.setPosition(titleEdge); jfreeChart.addSubtitle(subtitle); } // Apply all of the legend formatting options LegendTitle legend = jfreeChart.getLegend(); if (legend != null) { legend.setItemPaint(getChart().getLegendColor()); if (getChart().getOwnLegendBackgroundColor() == null)// in a way, legend backcolor inheritance from chart is useless { legend.setBackgroundPaint(null); } else { legend.setBackgroundPaint(getChart().getLegendBackgroundColor()); } legend.setItemFont(fontUtil.getAwtFont(getFont(getChart().getLegendFont()), getLocale())); legend.setPosition(getEdge(getChart().getLegendPositionValue(), RectangleEdge.BOTTOM)); } configurePlot(jfreeChart.getPlot()); }
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private void setLegend(JFreeChart chart, boolean bShowLegend, Font font, Color foregroundColor, Color backgroundColor, cfCHARTLEGENDData legendData) throws cfmRunTimeException { LegendTitle legend = new LegendTitle(chart.getPlot()); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); // If a CFCHARTLEGEND tag was used then use it's attributes to configure the // legend/*from w ww .j a va 2 s . c o m*/ if (legendData != null) { // A CFCHARTLEGEND tag is present so use its attributes to configure the // legend legend.setItemFont(getFont(legendData.getFont(), legendData.getFontBold(), legendData.getFontItalic(), legendData.getFontSize())); legend.setItemPaint(convertStringToColor(legendData.getLabelColor())); legend.setBackgroundPaint(convertStringToColor(legendData.getBackgroundColor())); String pos = legendData.getPosition(); if (pos.equals("top")) legend.setPosition(RectangleEdge.TOP); else if (pos.equals("bottom")) legend.setPosition(RectangleEdge.BOTTOM); else if (pos.equals("left")) legend.setPosition(RectangleEdge.LEFT); else if (pos.equals("right")) legend.setPosition(RectangleEdge.RIGHT); if (!legendData.getShowBorder()) legend.setBorder(BlockBorder.NONE); else legend.setBorder(new BlockBorder()); } else { // A CFCHARTLEGEND tag is NOT present so use the attributes from the // CFCHART tag to configure the legend if (!bShowLegend) return; legend.setItemFont(font); legend.setItemPaint(foregroundColor); legend.setBackgroundPaint(backgroundColor); // By default CFMX 7 places the legend at the top with no border legend.setPosition(RectangleEdge.TOP); legend.setBorder(BlockBorder.NONE); } // Add the legend to the chart chart.addSubtitle(legend); }
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(); }/* w ww .ja v a2s. c om*/ 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 av a 2 s .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)); } }