Example usage for org.jfree.chart JFreeChart setBackgroundPaint

List of usage examples for org.jfree.chart JFreeChart setBackgroundPaint

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart setBackgroundPaint.

Prototype

public void setBackgroundPaint(Paint paint) 

Source Link

Document

Sets the paint used to fill the chart background and sends a ChartChangeEvent to all registered listeners.

Usage

From source file:cit.workflow.engine.manager.test.SWTTimeSeriesDemo.java

/**
 * Creates a chart.// ww  w .j  a v a  2 s .  c  o 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
            true, // 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);

    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"));

    return chart;

}

From source file:service.chart.FitnessChart.java

/**
 * Utworz wykres funkcji fitness dla najlepszego osobnika w danej iteracji algorytmu genetycznego 
 * na podstawie zestawu danych//  w  w  w  .j  a  v  a 2  s.  c  o  m
 * 
 * @param categoryDataset Zestaw danych
 * @return Wykres funkcji fitness
 */
private static JFreeChart createChart(CategoryDataset categoryDataset) {

    JFreeChart chart = ChartFactory.createLineChart("Best fitness function value", // title
            "Iteration", // x-axis label
            "Fitness", // y-axis label
            categoryDataset, // data
            PlotOrientation.VERTICAL, true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    CategoryItemRenderer r = plot.getRenderer();
    if (r instanceof LineAndShapeRenderer) {
        LineAndShapeRenderer renderer = (LineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setBaseShapesFilled(true);
    }

    return chart;
}

From source file:org.jfree.chart.demo.SymbolicXYPlotDemo.java

/**
 * Displays an XYPlot with symbolic axes.
 * /*from w ww.j  av a 2s  .c om*/
 * @param frameTitle
 *           the frame title.
 * @param data
 *           the dataset.
 * @param chartTitle
 *           the chart title.
 * @param xAxisLabel
 *           the x axis label.
 * @param yAxisLabel
 *           the y axis label.
 */
private static void displayXYSymbolic(final String frameTitle, final XYDataset data, final String chartTitle,
        final String xAxisLabel, final String yAxisLabel) {

    final JFreeChart chart = createXYSymbolicPlot(chartTitle, xAxisLabel, yAxisLabel, data, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.green));
    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}

From source file:tools.descartes.bungee.chart.ChartGenerator.java

private static void chartCustomization(final JFreeChart chart) {
    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    customizePlot(plot);/*from ww  w .  j  a va 2  s  .co m*/
}

From source file:graficos.GraficoGantt.java

private static JFreeChart crearGrafico(IntervalCategoryDataset cjto_datos) {
    JFreeChart grafico = ChartFactory.createGanttChart("Diagrama de Gantt", // Ttulo
            "Actividad", // Ttulo eje x
            "Fecha", // Ttulo eje y
            cjto_datos, // Datos
            true, // Incluir leyenda
            true, // Incluir tooltips
            false // Incluir URLs
    );/*from   w w w .j  av a  2s .co m*/
    grafico.setBackgroundPaint(new Color(240, 240, 240));
    grafico.getPlot().zoom(0.0);
    CategoryPlot categoriaPlot = (CategoryPlot) grafico.getPlot();
    GanttRenderer renderer = (GanttRenderer) categoriaPlot.getRenderer();
    renderer.setDrawBarOutline(true);
    // GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, new Color(102, 255, 102), 0.0f, 0.0f, new Color(102, 255, 102));
    renderer.setSeriesPaint(0, new Color(48, 239, 48));
    renderer.setSeriesPaint(1, Color.RED);
    grafico.getPlot().setOutlineVisible(true);
    return grafico;
}

From source file:com.controlj.addon.gwttree.server.GraphServlet.java

/**<!====== getChart ======================================================>
   Generates the chart.  Note that most of these options are not required
   for a simple chart, but we wanted to try to get a particular look that
   matched another charting package, so we went to some trouble to set
   a lot of non-standard options.  In particular, the OpaqueBarRenderer3D
   is a non-standard renderer that gives much better looking 3D bars.
<!=======================================================================>*/
private static JFreeChart getChart(DefaultCategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart3D("Integration Over Time", "24 Hour Period", "", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.black);
    chart.getTitle().setPaint(Color.white);
    chart.getTitle().setFont(new Font("Verdana", Font.BOLD, 20));
    chart.setAntiAlias(true);/*w  w w . j a  v  a2 s.  co  m*/
    chart.setTextAntiAlias(true);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setForegroundAlpha(1);
    OpaqueBarRenderer3D renderer = new OpaqueBarRenderer3D();
    renderer.setItemMargin(0.1);
    plot.setRenderer(renderer);

    renderer.setSeriesPaint(0, new Color(116, 225, 118));
    renderer.setSeriesPaint(1, new Color(245, 107, 107));
    renderer.setSeriesPaint(2, new Color(250, 187, 107));
    renderer.setSeriesPaint(3, new Color(72, 72, 238));
    renderer.setSeriesPaint(4, new Color(184, 32, 157));
    renderer.setDrawBarOutline(false);

    Font small = new Font("Verdana", Font.PLAIN, 12);
    Font big = new Font("Verdana", Font.BOLD, 14);

    renderer.setItemLabelPaint(Color.white);
    plot.getDomainAxis().setTickLabelPaint(Color.white);
    plot.getDomainAxis().setTickLabelFont(small);
    plot.getDomainAxis().setLabelPaint(Color.white);
    plot.getDomainAxis().setLabelFont(big);
    plot.getDomainAxis().setCategoryMargin(0.2);

    plot.getRangeAxis().setTickLabelPaint(Color.white);
    plot.getRangeAxis().setTickLabelFont(small);
    plot.getRangeAxis().setLabelPaint(Color.white);
    plot.getRangeAxis().setLabelFont(big);
    plot.setBackgroundPaint(Color.black);

    chart.getLegend().setBackgroundPaint(Color.black);
    chart.getLegend().setItemPaint(Color.white);
    chart.getLegend().setItemFont(big);

    return chart;
}

From source file:com.opensourcestrategies.crmsfa.reports.JFreeCrmsfaCharts.java

/**
 * Lead pipeline.  Description at http://www.opentaps.org/docs/index.php/CRMSFA_Dashboard
 * Note that this counts all the leads in the system for now.
 *//* w  w w .  jav a 2  s. c  o m*/
public static String createLeadPipelineChart(Delegator delegator, Locale locale)
        throws GenericEntityException, IOException {
    Map uiLabelMap = UtilMessage.getUiLabels(locale);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // get all LEAD statuses that are not CONVERTED, or DEAD
    List<GenericValue> leadStatuses = ReportHelper.findLeadStatusesForDashboardReporting(delegator);

    // report number of leads for each status
    for (GenericValue status : leadStatuses) {
        String statusId = status.getString("statusId");
        long count = delegator.findCountByCondition("PartyAndStatus",
                EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, statusId), null);
        dataset.addValue(count, "", (String) status.get("description", locale));
    }

    // set up the chart
    JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("CrmLeadPipeline"), null, null,
            dataset, PlotOrientation.HORIZONTAL, false, true, false);
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // get the bar renderer to put effects on the bars
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false); // disable bar outlines

    // set up gradient paint on bar
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, new Color(227, 246, 206), 0.0f, 0.0f,
            new Color(153, 204, 102));
    renderer.setSeriesPaint(0, gp);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // save as a png and return the file name
    return ServletUtilities.saveChartAsPNG(chart, 360, 200, null);
}

From source file:net.sf.jasperreports.components.spiderchart.SpiderChartDesignEvaluator.java

/**
 * /*w  w  w  . ja v  a2 s .  c om*/
 */
public static JRRenderable evaluateRenderer(ReportConverter reportConverter, JRComponentElement element) {
    SpiderChartComponent chartComponent = (SpiderChartComponent) element.getComponent();
    ChartSettings chartSettings = chartComponent.getChartSettings();
    SpiderPlot plot = chartComponent.getPlot();

    SpiderWebPlot spiderWebPlot = new SpiderWebPlot(getSampleDataset());

    if (plot.getAxisLineColor() != null) {
        spiderWebPlot.setAxisLinePaint(plot.getAxisLineColor());
    }
    if (plot.getAxisLineWidth() != null) {
        spiderWebPlot.setAxisLineStroke(new BasicStroke(plot.getAxisLineWidth()));
    }
    if (plot.getBackcolor() != null) {
        spiderWebPlot.setBackgroundPaint(plot.getBackcolor());
    }
    if (plot.getBackgroundAlpha() != null) {
        spiderWebPlot.setBackgroundAlpha(plot.getBackgroundAlpha());
    }
    if (plot.getForegroundAlpha() != null) {
        spiderWebPlot.setForegroundAlpha(plot.getForegroundAlpha());
    }
    if (plot.getHeadPercent() != null) {
        spiderWebPlot.setHeadPercent(plot.getHeadPercent());
    }
    if (plot.getInteriorGap() != null) {
        spiderWebPlot.setInteriorGap(plot.getInteriorGap());
    }
    if (plot.getLabelColor() != null) {
        spiderWebPlot.setLabelPaint(plot.getLabelColor());
    }
    if (plot.getLabelFont() != null) {
        spiderWebPlot.setLabelFont(JRFontUtil.getAwtFont(plot.getLabelFont(), Locale.getDefault()));
    }
    if (plot.getLabelGap() != null) {
        spiderWebPlot.setAxisLabelGap(plot.getLabelGap());
    }

    spiderWebPlot.setMaxValue(MAX_VALUE);

    if (plot.getRotation() != null) {
        spiderWebPlot.setDirection(plot.getRotation().getRotation());
    }
    if (plot.getStartAngle() != null) {
        spiderWebPlot.setStartAngle(plot.getStartAngle());
    }
    if (plot.getTableOrder() != null) {
        spiderWebPlot.setDataExtractOrder(plot.getTableOrder().getOrder());
    }
    if (plot.getWebFilled() != null) {
        spiderWebPlot.setWebFilled(plot.getWebFilled());
    }

    spiderWebPlot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    spiderWebPlot.setLabelGenerator(new StandardCategoryItemLabelGenerator());

    String titleText = JRExpressionUtil.getExpressionText(chartSettings.getTitleExpression());

    Font titleFont = chartSettings.getTitleFont() != null
            ? JRFontUtil.getAwtFont(chartSettings.getTitleFont(), Locale.getDefault())
            : TextTitle.DEFAULT_FONT;

    JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true);

    if (chartSettings.getBackcolor() != null) {
        jfreechart.setBackgroundPaint(chartSettings.getBackcolor());
    }

    RectangleEdge titleEdge = getEdge(chartSettings.getTitlePosition(), RectangleEdge.TOP);

    if (titleText != null) {
        TextTitle title = jfreechart.getTitle();
        title.setText(titleText);
        if (chartSettings.getTitleColor() != null) {
            title.setPaint(chartSettings.getTitleColor());
        }

        title.setFont(titleFont);
        title.setPosition(titleEdge);
        jfreechart.setTitle(title);
    }

    String subtitleText = JRExpressionUtil.getExpressionText(chartSettings.getSubtitleExpression());
    if (subtitleText != null) {
        TextTitle subtitle = new TextTitle(subtitleText);
        subtitle.setText(subtitleText);
        if (chartSettings.getSubtitleColor() != null) {
            subtitle.setPaint(chartSettings.getSubtitleColor());
        }

        if (chartSettings.getSubtitleColor() != null) {
            Font subtitleFont = chartSettings.getSubtitleFont() != null
                    ? JRFontUtil.getAwtFont(chartSettings.getSubtitleFont(), Locale.getDefault())
                    : TextTitle.DEFAULT_FONT;
            subtitle.setFont(subtitleFont);
        }

        subtitle.setPosition(titleEdge);

        jfreechart.addSubtitle(subtitle);
    }

    // Apply all of the legend formatting options
    LegendTitle legend = jfreechart.getLegend();
    if (legend != null) {
        legend.setVisible((chartSettings.getShowLegend() == null || chartSettings.getShowLegend()));
        if (legend.isVisible()) {
            if (chartSettings.getLegendColor() != null) {
                legend.setItemPaint(chartSettings.getLegendColor());
            }
            if (chartSettings.getLegendBackgroundColor() != null) {
                legend.setBackgroundPaint(chartSettings.getLegendBackgroundColor());
            }

            if (chartSettings.getLegendFont() != null) {
                legend.setItemFont(JRFontUtil.getAwtFont(chartSettings.getLegendFont(), Locale.getDefault()));
            }
            legend.setPosition(getEdge(chartSettings.getLegendPosition(), RectangleEdge.BOTTOM));
        }
    }

    Rectangle2D rectangle = new Rectangle2D.Double(0, 0, element.getWidth(), element.getHeight());

    String renderType = chartSettings.getRenderType();
    if (renderType == null) {
        renderType = JRProperties.getProperty(reportConverter.getReport(), JRChart.PROPERTY_CHART_RENDER_TYPE);
    }

    return ChartUtil.getChartRendererFactory(renderType).getRenderer(jfreechart, null, rectangle);
}

From source file:org.jfree.chart.demo.SymbolicYPlotDemo.java

/**
 * Create and display an overlaid chart.
 * //ww  w  . j av  a2 s  .c o  m
 * @param frameTitle
 *           the frame title.
 * @param data1
 *           dataset1.
 * @param data2
 *           dataset2.
 */
private static void displayYSymbolicOverlaid(final String frameTitle, final XYDataset data1,
        final XYDataset data2) {

    final String title = "Animals Overlaid";
    final String xAxisLabel = "Miles";
    final String yAxisLabel = "Animal";

    // combine the y symbolic values of the two data sets...
    final String[] combinedYSymbolicValues = SampleYSymbolicDataset.combineYSymbolicDataset((YisSymbolic) data1,
            (YisSymbolic) data2);

    // make master dataset...
    final CombinedDataset data = new CombinedDataset();
    data.add(data1);
    data.add(data2);

    // decompose data...
    final XYDataset series0 = new SubSeriesDataset(data, 0);
    final XYDataset series1 = new SubSeriesDataset(data, 1);
    final XYDataset series2 = new SubSeriesDataset(data, 2);
    final XYDataset series3 = new SubSeriesDataset(data, 3);
    final XYDataset series4 = new SubSeriesDataset(data, 4);
    final XYDataset series5 = new SubSeriesDataset(data, 5);
    final XYDataset series6 = new SubSeriesDataset(data, 6);
    final XYDataset series7 = new SubSeriesDataset(data, 7);

    // create main plot...
    final ValueAxis valueAxis = new NumberAxis(xAxisLabel);
    final SymbolicAxis symbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues);
    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot plot = new XYPlot(series0, valueAxis, symbolicAxis, renderer);

    plot.setDataset(1, series1);
    final XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(1, renderer1);

    plot.setDataset(2, series2);
    final XYItemRenderer renderer2 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(2, renderer2);

    plot.setDataset(3, series3);
    final XYItemRenderer renderer3 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(3, renderer3);

    plot.setDataset(4, series4);
    final XYItemRenderer renderer4 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(4, renderer4);

    plot.setDataset(5, series5);
    final XYItemRenderer renderer5 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(5, renderer5);

    plot.setDataset(6, series6);
    final XYItemRenderer renderer6 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(6, renderer6);

    plot.setDataset(7, series7);
    final XYItemRenderer renderer7 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    plot.setRenderer(7, renderer7);

    // make the chart...
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    // and present it in a frame...
    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}

From source file:org.jfree.chart.demo.SymbolicYPlotDemo.java

/**
 * Displays a vertically combined symbolic plot.
 * //from   w ww .j  a  v a2  s . c o  m
 * @param frameTitle
 *           the frame title.
 * @param data1
 *           dataset 1.
 * @param data2
 *           dataset 2.
 */
private static void displayYSymbolicCombinedVertically(final String frameTitle,
        final SampleYSymbolicDataset data1, final SampleYSymbolicDataset data2) {

    final String title = "Animals Vertically Combined";
    final String xAxisLabel = "Miles";
    final String yAxisLabel = null;

    // create master dataset...
    final CombinedDataset data = new CombinedDataset();
    data.add(data1);
    data.add(data2);

    // decompose data...
    final XYDataset series0 = new SubSeriesDataset(data, 0);
    final XYDataset series1 = new SubSeriesDataset(data, 1);
    final XYDataset series2 = new SubSeriesDataset(data, 2);
    final XYDataset series3 = new SubSeriesDataset(data, 3);
    final XYDataset series4 = new SubSeriesDataset(data, 4);
    final XYDataset series5 = new SubSeriesDataset(data, 5);
    final XYDataset series6 = new SubSeriesDataset(data, 6);
    final XYDataset series7 = new SubSeriesDataset(data, 7);

    // common horizontal and vertical axes
    final ValueAxis valueAxis = new NumberAxis(xAxisLabel);
    final SymbolicAxis symbolicAxis1 = new SymbolicAxis(yAxisLabel, ((YisSymbolic) data1).getYSymbolicValues());
    final SymbolicAxis symbolicAxis2 = new SymbolicAxis(yAxisLabel, ((YisSymbolic) data2).getYSymbolicValues());

    // create the main plot...
    final CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(valueAxis);

    // and the sub-plots...
    final XYItemRenderer renderer0 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot0 = new XYPlot(series0, null, symbolicAxis1, renderer0);
    final XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot1 = new XYPlot(series1, null, symbolicAxis1, renderer1);
    final XYItemRenderer renderer2 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot2 = new XYPlot(series2, null, symbolicAxis1, renderer2);
    final XYItemRenderer renderer3 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot3 = new XYPlot(series3, null, symbolicAxis1, renderer3);
    final XYItemRenderer renderer4 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot4 = new XYPlot(series4, null, symbolicAxis2, renderer4);
    final XYItemRenderer renderer5 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot5 = new XYPlot(series5, null, symbolicAxis2, renderer5);
    final XYItemRenderer renderer6 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot6 = new XYPlot(series6, null, symbolicAxis2, renderer6);
    final XYItemRenderer renderer7 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
    final XYPlot subplot7 = new XYPlot(series7, null, symbolicAxis2, renderer7);

    // add the subplots to the main plot...
    mainPlot.add(subplot0, 1);
    mainPlot.add(subplot1, 1);
    mainPlot.add(subplot2, 1);
    mainPlot.add(subplot3, 1);
    mainPlot.add(subplot4, 1);
    mainPlot.add(subplot5, 1);
    mainPlot.add(subplot6, 1);
    mainPlot.add(subplot7, 1);

    // construct the chart...
    final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue));

    // and present it in a frame...
    final JFrame frame = new ChartFrame(frameTitle, chart);
    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.show();

}