Example usage for org.jfree.chart StandardChartTheme setPlotBackgroundPaint

List of usage examples for org.jfree.chart StandardChartTheme setPlotBackgroundPaint

Introduction

In this page you can find the example usage for org.jfree.chart StandardChartTheme setPlotBackgroundPaint.

Prototype

public void setPlotBackgroundPaint(Paint paint) 

Source Link

Document

Sets the plot background paint.

Usage

From source file:com.uttesh.pdfngreport.util.chart.ChartStyle.java

/**
 * this method will set the style theme for pie chart.
 *
 * @see org.jfree.chart.StandardChartTheme
 * @param chart/*from   ww  w . j av a  2 s . c  o  m*/
 */
public static void theme(JFreeChart chart) {
    String fontName = "Lucida Sans";

    StandardChartTheme theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();

    theme.setTitlePaint(Color.decode("#4572a7"));
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 16)); //title
    theme.setLargeFont(new Font(fontName, Font.BOLD, 15)); //axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 11));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    theme.apply(chart);
    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
}

From source file:jamel.gui.charts.JamelChart.java

/**
 * Returns the standard chart theme.//from   w w  w  .  java 2s .  com
 * @return the standard chart theme.
 */
private static StandardChartTheme getNewChartTheme() {
    StandardChartTheme theme = new StandardChartTheme("Standard Chart Theme");
    float size = theme.getExtraLargeFont().getSize2D();
    Font titleFont = theme.getExtraLargeFont().deriveFont(size - 4);
    theme.setExtraLargeFont(titleFont);
    Font axisFont = theme.getRegularFont();
    theme.setLargeFont(axisFont);
    theme.setChartBackgroundPaint(new Color(0, 0, 0, 1));
    theme.setPlotBackgroundPaint(Color.WHITE);
    theme.setDomainGridlinePaint(Color.GRAY);
    theme.setRangeGridlinePaint(Color.GRAY);
    return theme;
}

From source file:org.yccheok.jstock.charting.Utils.java

/**
 * Applying chart theme based on given JFreeChart.
 *
 * @param chart the JFreeChart/* w  w  w  .  ja  va  2  s  .  co m*/
 */
public static void applyChartTheme(JFreeChart chart) {
    final StandardChartTheme chartTheme = (StandardChartTheme) org.jfree.chart.StandardChartTheme
            .createJFreeTheme();
    chartTheme.setXYBarPainter(barPainter);
    chartTheme.setShadowVisible(false);
    chartTheme.setPlotBackgroundPaint(Color.WHITE);
    chartTheme.setDomainGridlinePaint(Color.LIGHT_GRAY);
    chartTheme.setRangeGridlinePaint(Color.LIGHT_GRAY);
    chartTheme.setPlotOutlinePaint(Color.LIGHT_GRAY);

    // The default font used by JFreeChart unable to render Chinese properly.
    // We need to provide font which is able to support Chinese rendering.
    final Locale defaultLocale = Locale.getDefault();
    if (org.yccheok.jstock.gui.Utils.isSimplifiedChinese(defaultLocale)
            || org.yccheok.jstock.gui.Utils.isTraditionalChinese(defaultLocale)) {
        final Font oldExtraLargeFont = chartTheme.getExtraLargeFont();
        final Font oldLargeFont = chartTheme.getLargeFont();
        final Font oldRegularFont = chartTheme.getRegularFont();
        final Font oldSmallFont = chartTheme.getSmallFont();

        final Font extraLargeFont = new Font("Sans-serif", oldExtraLargeFont.getStyle(),
                oldExtraLargeFont.getSize());
        final Font largeFont = new Font("Sans-serif", oldLargeFont.getStyle(), oldLargeFont.getSize());
        final Font regularFont = new Font("Sans-serif", oldRegularFont.getStyle(), oldRegularFont.getSize());
        final Font smallFont = new Font("Sans-serif", oldSmallFont.getStyle(), oldSmallFont.getSize());

        chartTheme.setExtraLargeFont(extraLargeFont);
        chartTheme.setLargeFont(largeFont);
        chartTheme.setRegularFont(regularFont);
        chartTheme.setSmallFont(smallFont);
    }

    if (chart.getPlot() instanceof CombinedDomainXYPlot) {
        @SuppressWarnings("unchecked")
        List<Plot> plots = ((CombinedDomainXYPlot) chart.getPlot()).getSubplots();
        for (Plot plot : plots) {
            final int domainAxisCount = ((XYPlot) plot).getDomainAxisCount();
            final int rangeAxisCount = ((XYPlot) plot).getRangeAxisCount();
            for (int i = 0; i < domainAxisCount; i++) {
                ((XYPlot) plot).getDomainAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                ((XYPlot) plot).getDomainAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
            for (int i = 0; i < rangeAxisCount; i++) {
                ((XYPlot) plot).getRangeAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                ((XYPlot) plot).getRangeAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
        }
    } else {
        final Plot plot = chart.getPlot();
        if (plot instanceof XYPlot) {
            final org.jfree.chart.plot.XYPlot xyPlot = (org.jfree.chart.plot.XYPlot) plot;
            final int domainAxisCount = xyPlot.getDomainAxisCount();
            final int rangeAxisCount = xyPlot.getRangeAxisCount();
            for (int i = 0; i < domainAxisCount; i++) {
                xyPlot.getDomainAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                xyPlot.getDomainAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
            for (int i = 0; i < rangeAxisCount; i++) {
                xyPlot.getRangeAxis(i).setAxisLinePaint(Color.LIGHT_GRAY);
                xyPlot.getRangeAxis(i).setTickMarkPaint(Color.LIGHT_GRAY);
            }
        }
        //else if (plot instanceof org.jfree.chart.plot.PiePlot) {
        //    final org.jfree.chart.plot.PiePlot piePlot = (org.jfree.chart.plot.PiePlot)plot;
        //    
        //}
    }

    chartTheme.apply(chart);
}