Example usage for org.jfree.chart.plot Plot setBackgroundAlpha

List of usage examples for org.jfree.chart.plot Plot setBackgroundAlpha

Introduction

In this page you can find the example usage for org.jfree.chart.plot Plot setBackgroundAlpha.

Prototype

public void setBackgroundAlpha(float alpha) 

Source Link

Document

Sets the alpha transparency of the plot area background, and notifies registered listeners that the plot has been modified.

Usage

From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java

public static void customizePlot(Plot plot, ChartParams params) {
    if (params.get(ChartParams.PLOT_BACKGROUND_COLOR) != null) {
        plot.setBackgroundPaint(params.getColor(ChartParams.PLOT_BACKGROUND_COLOR));
    }/*from  ww w .j  av a  2  s  . c om*/

    if (params.get(ChartParams.PLOT_BACKGROUND_ALPHA) != null) {
        plot.setBackgroundAlpha(params.getFloat(ChartParams.PLOT_BACKGROUND_ALPHA).floatValue());
    }

    if (params.get(ChartParams.PLOT_FOREGROUND_ALPHA) != null) {
        plot.setForegroundAlpha(params.getFloat(ChartParams.PLOT_FOREGROUND_ALPHA).floatValue());
    }

    if (params.get(ChartParams.PLOT_INSERTS) != null) {
        plot.setInsets(params.getRectangleInsets(ChartParams.PLOT_INSERTS));
    }

    if (params.get(ChartParams.PLOT_OUTLINE_COLOR) != null) {
        plot.setOutlinePaint(params.getColor(ChartParams.PLOT_OUTLINE_COLOR));
    }

    if (params.get(ChartParams.PLOT_OUTLINE_STROKE) != null) {
        plot.setOutlineStroke(params.getStroke(ChartParams.PLOT_OUTLINE_STROKE));
    }
}

From source file:com.igalia.java.zk.components.JFreeChartEngine.java

public byte[] drawChart(Object data) {
    Chart chart = (Chart) data;/*from   w  w  w.j av a  2 s.  com*/
    ChartImpl impl = getChartImpl(chart);
    JFreeChart jfchart = impl.createChart(chart);

    Plot plot = (Plot) jfchart.getPlot();
    float alpha = (float) (((float) chart.getFgAlpha()) / 255);
    plot.setForegroundAlpha(alpha);

    alpha = (float) (((float) chart.getBgAlpha()) / 255);
    plot.setBackgroundAlpha(alpha);

    int[] bgRGB = chart.getBgRGB();
    if (bgRGB != null) {
        plot.setBackgroundPaint(new Color(bgRGB[0], bgRGB[1], bgRGB[2], chart.getBgAlpha()));
    }

    int[] paneRGB = chart.getPaneRGB();
    if (paneRGB != null) {
        jfchart.setBackgroundPaint(new Color(paneRGB[0], paneRGB[1], paneRGB[2], chart.getPaneAlpha()));
    }

    //since 3.6.3, JFreeChart 1.0.13 change default fonts which does not support Chinese, allow
    //developer to set font.

    //title font
    final Font tfont = chart.getTitleFont();
    if (tfont != null) {
        jfchart.getTitle().setFont(tfont);
    }

    //legend font
    final Font lfont = chart.getLegendFont();
    if (lfont != null) {
        jfchart.getLegend().setItemFont(lfont);
    }

    if (plot instanceof CategoryPlot) {
        final CategoryPlot cplot = (CategoryPlot) plot;
        cplot.setRangeGridlinePaint(new Color(0xc0, 0xc0, 0xc0));

        //Domain axis(x axis)
        final Font xlbfont = chart.getXAxisFont();
        final Font xtkfont = chart.getXAxisTickFont();
        if (xlbfont != null) {
            cplot.getDomainAxis().setLabelFont(xlbfont);
        }
        if (xtkfont != null) {
            cplot.getDomainAxis().setTickLabelFont(xtkfont);
        }

        Color[] colorMappings = (Color[]) chart.getAttribute("series-color-mappings");
        if (colorMappings != null) {
            for (int ii = 0; ii < colorMappings.length; ii++) {
                cplot.getRenderer().setSeriesPaint(ii, colorMappings[ii]);
            }
        }

        Double lowerBound = (Double) chart.getAttribute("range-axis-lower-bound");
        if (lowerBound != null) {
            cplot.getRangeAxis().setAutoRange(false);
            cplot.getRangeAxis().setLowerBound(lowerBound);
        }

        Double upperBound = (Double) chart.getAttribute("range-axis-upper-bound");
        if (upperBound != null) {
            cplot.getRangeAxis().setAutoRange(false);
            cplot.getRangeAxis().setUpperBound(upperBound);
        }

        //Range axis(y axis)
        final Font ylbfont = chart.getYAxisFont();
        final Font ytkfont = chart.getYAxisTickFont();
        if (ylbfont != null) {
            cplot.getRangeAxis().setLabelFont(ylbfont);
        }
        if (ytkfont != null) {
            cplot.getRangeAxis().setTickLabelFont(ytkfont);
        }
    } else if (plot instanceof XYPlot) {
        final XYPlot xyplot = (XYPlot) plot;
        xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);

        //Domain axis(x axis)
        final Font xlbfont = chart.getXAxisFont();
        final Font xtkfont = chart.getXAxisTickFont();
        if (xlbfont != null) {
            xyplot.getDomainAxis().setLabelFont(xlbfont);
        }
        if (xtkfont != null) {
            xyplot.getDomainAxis().setTickLabelFont(xtkfont);
        }

        //Range axis(y axis)
        final Font ylbfont = chart.getYAxisFont();
        final Font ytkfont = chart.getYAxisTickFont();
        if (ylbfont != null) {
            xyplot.getRangeAxis().setLabelFont(ylbfont);
        }
        if (ytkfont != null) {
            xyplot.getRangeAxis().setTickLabelFont(ytkfont);
        }
    } else if (plot instanceof PiePlot) {
        plot.setOutlineStroke(null);
    }

    //callbacks for each area
    ChartRenderingInfo jfinfo = new ChartRenderingInfo();
    BufferedImage bi = jfchart.createBufferedImage(chart.getIntWidth(), chart.getIntHeight(),
            Transparency.TRANSLUCENT, jfinfo);

    //remove old areas
    if (chart.getChildren().size() > 20)
        chart.invalidate(); //improve performance if too many chart
    chart.getChildren().clear();

    if (Events.isListened(chart, Events.ON_CLICK, false) || chart.isShowTooltiptext()) {
        int j = 0;
        String preUrl = null;
        for (Iterator it = jfinfo.getEntityCollection().iterator(); it.hasNext();) {
            ChartEntity ce = (ChartEntity) it.next();
            final String url = ce.getURLText();

            //workaround JFreeChart's bug (skip replicate areas)
            if (url != null) {
                if (preUrl == null) {
                    preUrl = url;
                } else if (url.equals(preUrl)) { //start replicate, skip
                    break;
                }
            }

            //1. JFreeChartEntity area cover the whole chart, will "mask" other areas
            //2. LegendTitle area cover the whole legend, will "mask" each legend
            //3. PlotEntity cover the whole chart plotting araa, will "mask" each bar/line/area
            if (!(ce instanceof JFreeChartEntity)
                    && !(ce instanceof TitleEntity && ((TitleEntity) ce).getTitle() instanceof LegendTitle)
                    && !(ce instanceof PlotEntity)) {
                Area area = new Area();
                area.setParent(chart);
                area.setCoords(ce.getShapeCoords());
                area.setShape(ce.getShapeType());
                area.setId("area_" + chart.getId() + '_' + (j++));
                if (chart.isShowTooltiptext() && ce.getToolTipText() != null) {
                    area.setTooltiptext(ce.getToolTipText());
                }
                area.setAttribute("url", ce.getURLText());
                impl.render(chart, area, ce);
                if (chart.getAreaListener() != null) {
                    try {
                        chart.getAreaListener().onRender(area, ce);
                    } catch (Exception ex) {
                        throw UiException.Aide.wrap(ex);
                    }
                }
            }
        }
    }
    //clean up the "LEGEND_SEQ"
    //used for workaround LegendItemEntity.getSeries() always return 0
    //used for workaround TickLabelEntity no information
    chart.removeAttribute("LEGEND_SEQ");
    chart.removeAttribute("TICK_SEQ");

    try {
        //encode into png image format byte array
        return EncoderUtil.encode(bi, ImageFormat.PNG, true);
    } catch (java.io.IOException ex) {
        throw UiException.Aide.wrap(ex);
    }
}

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

protected void setChartStyles(JFreeChart chart, UIChart comp) {
    Plot plot = chart.getPlot();

    RectangleInsets insets = plot.getInsets();
    Double tm = comp.getTopMargin();
    Double lm = comp.getLeftMargin();
    Double bm = comp.getBottomMargin();
    Double rm = comp.getRightMargin();
    if (tm == null || tm < 0)
        tm = insets.getTop();/* w  ww  .  j  a v a  2  s.co m*/
    if (lm == null || lm < 0)
        lm = insets.getLeft();
    if (bm == null || bm < 0)
        bm = insets.getBottom();
    if (rm == null || rm < 0)
        rm = insets.getRight();
    plot.setInsets(new RectangleInsets(tm, lm, bm, rm));

    Paint color = comp.getBackgroundColor();
    if (color != null) {
        chart.setBackgroundPaint(color);
    }

    Image image = loadImage(comp.getBackgroundImage());
    if (image != null) {
        chart.setBackgroundImage(image);
        chart.setBackgroundImageAlignment(getImageAlign(comp.getBackgroundImagePosition()));
        chart.setBackgroundImageAlpha(comp.getBackgroundImageAlpha());
    }

    color = comp.getPlotColor();
    if (color != null) {
        plot.setBackgroundPaint(color);
    }

    Float alpha;
    if ((alpha = comp.getBackgroundAlpha()) != null) {
        plot.setBackgroundAlpha(alpha);
    }
    if ((alpha = comp.getForegroundAlpha()) != null) {
        plot.setForegroundAlpha(alpha);
    }

    image = loadImage(comp.getPlotImage());
    if (image != null) {
        plot.setBackgroundImage(image);
        plot.setBackgroundImageAlignment(getImageAlign(comp.getPlotImagePosition()));
        plot.setBackgroundImageAlpha(comp.getBackgroundImageAlpha());
    }

    Paint[] colorPalette = comp.getColorPalette();
    if (colorPalette != null) {
        plot.setDrawingSupplier(new CustomDrawingSupplier(colorPalette));
    } else {
        plot.setDrawingSupplier(new CustomDrawingSupplier());
    }
}

From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java

/**
 *
 *//*from   w  w  w  . jav a 2 s.  com*/
protected void configurePlot(Plot plot) {
    plot.setOutlinePaint(null);

    if (getPlot().getOwnBackcolor() == null)// in a way, plot backcolor inheritence from chart is useless
    {
        plot.setBackgroundPaint(null);
    } else {
        plot.setBackgroundPaint(getPlot().getBackcolor());
    }

    float backgroundAlpha = getPlot().getBackgroundAlphaFloat() == null ? 1f
            : getPlot().getBackgroundAlphaFloat();
    float foregroundAlpha = getPlot().getForegroundAlphaFloat() == null ? 1f
            : getPlot().getForegroundAlphaFloat();
    plot.setBackgroundAlpha(backgroundAlpha);
    plot.setForegroundAlpha(foregroundAlpha);

    if (plot instanceof CategoryPlot) {
        // Handle rotation of the category labels.
        CategoryAxis axis = ((CategoryPlot) plot).getDomainAxis();
        // it's OK to use deprecated method here; avoiding it means attempting cast operations  
        double labelRotation = getLabelRotation();
        if (labelRotation == 90) {
            axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
        } else if (labelRotation == -90) {
            axis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        } else if (labelRotation < 0) {
            axis.setCategoryLabelPositions(
                    CategoryLabelPositions.createUpRotationLabelPositions((-labelRotation / 180.0) * Math.PI));
        } else if (labelRotation > 0) {
            axis.setCategoryLabelPositions(
                    CategoryLabelPositions.createDownRotationLabelPositions((labelRotation / 180.0) * Math.PI));
        }
    }

    // Set any color series
    SortedSet<JRSeriesColor> seriesColors = getPlot().getSeriesColors();
    if (seriesColors != null && seriesColors.size() > 0) {
        if (seriesColors.size() == 1) {
            // Add the single color to the beginning of the color cycle, using all the default
            // colors.  To replace the defaults you have to specify at least two colors.
            Paint[] colors = new Paint[DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length + 1];
            colors[0] = seriesColors.first().getColor();
            System.arraycopy(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE, 0, colors, 1,
                    DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length);
            plot.setDrawingSupplier(
                    new DefaultDrawingSupplier(colors, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
        } else if (seriesColors.size() > 1) {
            // Set up a custom drawing supplier that cycles through the user's colors
            // instead of the default colors.
            Color[] colors = new Color[seriesColors.size()];
            JRSeriesColor[] colorSequence = new JRSeriesColor[seriesColors.size()];
            seriesColors.toArray(colorSequence);
            for (int i = 0; i < colorSequence.length; i++) {
                colors[i] = colorSequence[i].getColor();
            }

            plot.setDrawingSupplier(
                    new DefaultDrawingSupplier(colors, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
        }
    }
}

From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java

protected void setPlotBackground(Plot plot, JRChartPlot jrPlot) {
    PlotSettings plotSettings = getPlotSettings();
    Paint backgroundPaint = jrPlot.getOwnBackcolor();
    if (backgroundPaint == null && plotSettings.getBackgroundPaint() != null) {
        backgroundPaint = plotSettings.getBackgroundPaint().getPaint();
    }//w  ww . ja v a 2 s  .  c o m
    if (backgroundPaint == null) {
        backgroundPaint = ChartThemesConstants.TRANSPARENT_PAINT;
    }
    plot.setBackgroundPaint(backgroundPaint);

    Float backgroundAlpha = jrPlot.getBackgroundAlphaFloat();
    if (backgroundAlpha == null) {
        backgroundAlpha = plotSettings.getBackgroundAlpha();
    }
    if (backgroundAlpha != null)
        plot.setBackgroundAlpha(backgroundAlpha.floatValue());

    Float foregroundAlpha = jrPlot.getForegroundAlphaFloat();
    if (foregroundAlpha == null) {
        foregroundAlpha = plotSettings.getForegroundAlpha();
    }
    if (foregroundAlpha != null)
        plot.setForegroundAlpha(foregroundAlpha.floatValue());

    Image backgroundImage = plotSettings.getBackgroundImage() == null ? null
            : plotSettings.getBackgroundImage().getImage();
    if (backgroundImage != null) {
        plot.setBackgroundImage(backgroundImage);
        Integer backgroundImageAlignment = plotSettings.getBackgroundImageAlignment();
        if (backgroundImageAlignment != null) {
            plot.setBackgroundImageAlignment(backgroundImageAlignment.intValue());
        }
        Float backgroundImageAlpha = plotSettings.getBackgroundImageAlpha();
        if (backgroundImageAlpha != null) {
            plot.setBackgroundImageAlpha(backgroundImageAlpha.floatValue());
        }
    }
}

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

protected void setPlotBackground(Plot plot, JRChartPlot jrPlot) {
    PlotSettings plotSettings = getPlotSettings();
    Paint backgroundPaint = jrPlot.getOwnBackcolor();
    if (backgroundPaint == null && plotSettings.getBackgroundPaint() != null) {
        backgroundPaint = plotSettings.getBackgroundPaint().getPaint();
    }/*from w  w w.  ja  v a 2s.c o  m*/
    if (backgroundPaint == null) {
        backgroundPaint = ChartThemesConstants.TRANSPARENT_PAINT;
    }
    plot.setBackgroundPaint(backgroundPaint);

    Float backgroundAlpha = jrPlot.getBackgroundAlphaFloat();
    if (backgroundAlpha == null) {
        backgroundAlpha = plotSettings.getBackgroundAlpha();
    }
    if (backgroundAlpha != null)
        plot.setBackgroundAlpha(backgroundAlpha);

    Float foregroundAlpha = jrPlot.getForegroundAlphaFloat();
    if (foregroundAlpha == null) {
        foregroundAlpha = plotSettings.getForegroundAlpha();
    }
    if (foregroundAlpha != null)
        plot.setForegroundAlpha(foregroundAlpha);

    Image backgroundImage = plotSettings.getBackgroundImage() == null ? null
            : plotSettings.getBackgroundImage().getImage(getChartContext().getJasperReportsContext());
    if (backgroundImage != null) {
        plot.setBackgroundImage(backgroundImage);
        Integer backgroundImageAlignment = plotSettings.getBackgroundImageAlignment();
        if (backgroundImageAlignment != null) {
            plot.setBackgroundImageAlignment(backgroundImageAlignment);
        }
        Float backgroundImageAlpha = plotSettings.getBackgroundImageAlpha();
        if (backgroundImageAlpha != null) {
            plot.setBackgroundImageAlpha(backgroundImageAlpha);
        }
    }
}

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

protected void setPlotBackground(Plot p, JRChartPlot jrPlot) {
    Paint defaultBackgroundPaint = (Paint) getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_BACKGROUND_PAINT);
    Float defaultBackgroundAlpha = (Float) getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_BACKGROUND_ALPHA);
    Float defaultForegroundAlpha = (Float) getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_FOREGROUND_ALPHA);

    Image defaultBackgroundImage = (Image) getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_BACKGROUND_IMAGE);
    Integer defaultBackgroundImageAlignment = (Integer) getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_BACKGROUND_IMAGE_ALIGNMENT);
    Float defaultBackgroundImageAlpha = (Float) getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_BACKGROUND_IMAGE_ALPHA);

    Paint backgroundPaint = jrPlot.getOwnBackcolor() != null ? jrPlot.getOwnBackcolor()
            : defaultBackgroundPaint;/*from  ww  w .ja  v a2  s  .co m*/
    if (backgroundPaint != null) {
        p.setBackgroundPaint(backgroundPaint);
    }

    Float backgroundAlpha = jrPlot.getBackgroundAlphaFloat() != null ? jrPlot.getBackgroundAlphaFloat()
            : defaultBackgroundAlpha;
    if (backgroundAlpha != null)
        p.setBackgroundAlpha(backgroundAlpha.floatValue());

    Float foregroundAlpha = jrPlot.getForegroundAlphaFloat() != null ? jrPlot.getForegroundAlphaFloat()
            : defaultForegroundAlpha;
    if (foregroundAlpha != null)
        p.setForegroundAlpha(foregroundAlpha.floatValue());

    if (defaultBackgroundImage != null) {
        p.setBackgroundImage(defaultBackgroundImage);
        if (defaultBackgroundImageAlignment != null) {
            p.setBackgroundImageAlignment(defaultBackgroundImageAlignment.intValue());
        }
        if (defaultBackgroundImageAlpha != null) {
            p.setBackgroundImageAlpha(defaultBackgroundImageAlpha.floatValue());
        }
    }

}

From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java

protected void setPlotBackground(Plot p, JRChartPlot jrPlot) {
    Paint defaultBackgroundPaint = (Paint) getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_BACKGROUND_PAINT);
    Float defaultBackgroundAlpha = (Float) getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_BACKGROUND_ALPHA);
    Float defaultForegroundAlpha = (Float) getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_FOREGROUND_ALPHA);

    Image defaultBackgroundImage = (Image) getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_BACKGROUND_IMAGE);
    Integer defaultBackgroundImageAlignment = (Integer) getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_BACKGROUND_IMAGE_ALIGNMENT);
    Float defaultBackgroundImageAlpha = (Float) getDefaultValue(defaultPlotPropertiesMap,
            ChartThemesConstants.PLOT_BACKGROUND_IMAGE_ALPHA);

    Paint backgroundPaint = jrPlot.getOwnBackcolor() != null ? jrPlot.getOwnBackcolor()
            : defaultBackgroundPaint;//from   ww  w  .  j av a2 s .co m
    if (backgroundPaint != null) {
        p.setBackgroundPaint(backgroundPaint);
    }

    Float backgroundAlpha = jrPlot.getBackgroundAlphaFloat() != null ? jrPlot.getBackgroundAlphaFloat()
            : defaultBackgroundAlpha;
    if (backgroundAlpha != null)
        p.setBackgroundAlpha(backgroundAlpha);

    Float foregroundAlpha = jrPlot.getForegroundAlphaFloat() != null ? jrPlot.getForegroundAlphaFloat()
            : defaultForegroundAlpha;
    if (foregroundAlpha != null)
        p.setForegroundAlpha(foregroundAlpha);

    if (defaultBackgroundImage != null) {
        p.setBackgroundImage(defaultBackgroundImage);
        if (defaultBackgroundImageAlignment != null) {
            p.setBackgroundImageAlignment(defaultBackgroundImageAlignment);
        }
        if (defaultBackgroundImageAlpha != null) {
            p.setBackgroundImageAlpha(defaultBackgroundImageAlpha);
        }
    }

}