Example usage for org.jfree.chart.plot XYPlot setBackgroundPaint

List of usage examples for org.jfree.chart.plot XYPlot setBackgroundPaint

Introduction

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

Prototype

public void setBackgroundPaint(Paint paint) 

Source Link

Document

Sets the background color of the plot area and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:org.fhaes.fhsamplesize.view.SSIZCurveChart.java

/**
 * Create the chart./*from   w  w  w . j av a  2 s  . c o m*/
 * 
 * @param eventsPerCenturyDataset
 * @return
 */
private static JFreeChart createChart(final XYDataset eventsPerCenturyDataset, Integer xcross, Integer ycross) {

    // JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(null, "Number of series resampled", "Number of events",
    // eventsPerCenturyDataset, true, true, false);

    JFreeChart jfreechart = ChartFactory.createScatterPlot(null, "Number of series resampled",
            "Number of events per century", eventsPerCenturyDataset);

    jfreechart.setBackgroundPaint(Color.WHITE);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setInsets(new RectangleInsets(5D, 5D, 5D, 20D));
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    // xyplot.setDomainGridlinePaint(Color.white);
    // xyplot.setRangeGridlinePaint(Color.white);
    DeviationRenderer deviationrenderer = new DeviationRenderer(true, false);
    deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    deviationrenderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1));
    deviationrenderer.setSeriesFillPaint(0, new Color(255, 200, 200));
    deviationrenderer.setSeriesFillPaint(1, new Color(200, 200, 255));
    xyplot.setRenderer(deviationrenderer);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    jfreechart.removeLegend();

    if (xcross != null && ycross != null) {
        XYPlot xyp = jfreechart.getXYPlot();

        xyp.setRangeCrosshairVisible(true);
        xyp.setRangeCrosshairValue(ycross, true);
        xyp.setRangeCrosshairLockedOnData(true);

        xyp.setDomainCrosshairVisible(true);
        xyp.setDomainCrosshairValue(xcross, true);
        xyp.setDomainCrosshairLockedOnData(true);
    }

    // Initialize the chart variable for later use
    chart = jfreechart;

    return jfreechart;
}

From source file:projects.hip.exec.HrDiagram.java

/**
 * Plot the HR diagram chart from the given data.
 * @param series//from   w  w w  .ja v  a  2  s .  c o m
 *    A {@link XYSeries} containing the HR diagram data.
 * @return
 *    A {@link JFreeChart} containing the plot.
 */
private static JFreeChart getHrChart(XYSeries series) {

    XYSeriesCollection hrData = new XYSeriesCollection();
    hrData.addSeries(series);

    // Set up the renderer
    XYLineAndShapeRenderer hrRenderer = new XYLineAndShapeRenderer();

    hrRenderer.setSeriesLinesVisible(0, false);
    hrRenderer.setSeriesShapesVisible(0, true);
    hrRenderer.setSeriesShape(0, new Ellipse2D.Double(-0.5, -0.5, 1, 1));

    // Configure axes
    NumberAxis xAxis = new NumberAxis("B - V [mag]");
    xAxis.setRange(-0.5, 2.25);

    NumberAxis yAxis = new NumberAxis("H [mag]");
    yAxis.setInverted(true);
    yAxis.setRange(-5, 13);

    // Configure plot
    XYPlot xyplot = new XYPlot(hrData, xAxis, yAxis, hrRenderer);
    xyplot.setBackgroundPaint(Color.white);

    JFreeChart hrChart = new JFreeChart("HR diagram of Hipparcos stars", xyplot);
    hrChart.removeLegend();
    hrChart.setBackgroundPaint(Color.white);

    return hrChart;
}

From source file:projects.hip.exec.HrDiagram.java

/**
 * Plot the distribution of distance of all objects.
 * @param d_hist/*from   ww  w .  j  av a  2s .co  m*/
 *    The array containing the distance distribution histogram.
 * @return
 *    A {@link JFreeChart} containing the plot.
 */
private static JFreeChart getDistanceChart(double[] d_hist) {

    XYSeries series = new XYSeries("Distance distribution");

    for (int i = 0; i < d_hist.length; i++) {
        // Centre of this distance bin
        double d = d_min + i * d_step + d_step / 2.0;
        series.add(d, d_hist[i]);
    }
    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series);

    // Set up the renderer
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);

    // Configure axes
    NumberAxis xAxis = new NumberAxis("Distance [pc]");
    xAxis.setRange(d_min, d_max);

    NumberAxis yAxis = new NumberAxis("Number of objects");
    yAxis.setAutoRangeIncludesZero(true);

    // Configure plot
    XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer);
    xyplot.setBackgroundPaint(Color.white);

    JFreeChart dChart = new JFreeChart("Distance distribution of Hipparcos stars", xyplot);
    dChart.removeLegend();
    dChart.setBackgroundPaint(Color.white);

    return dChart;
}

From source file:grisu.frontend.view.swing.files.preview.fileViewers.JobStatusGridFileViewer.java

private static ChartPanel createChart(String title, String y_axis, XYDataset dataset, boolean createLegend) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            "Date", // x-axis label
            y_axis, // y-axis label
            dataset, // data
            createLegend, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );//from   www.j  a v a  2s  . c om

    chart.setBackgroundPaint(Color.white);

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

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);

    final XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("dd.MM. HH:mm"));

    return new ChartPanel(chart);

}

From source file:org.gephi.statistics.plugin.ChartUtils.java

public static void decorateChart(JFreeChart chart) {
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(0, 0, 2, 2));
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainGridlinePaint(java.awt.Color.GRAY);
    plot.setRangeGridlinePaint(java.awt.Color.GRAY);
    plot.setRenderer(renderer);/*w w  w .  j ava  2s . com*/
}

From source file:com.rapidminer.gui.plotter.charts.ParallelPlotter2.java

private static JFreeChart createChart(XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );/*from w  w  w.ja  va 2s .c o  m*/

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customization...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);

    ValueAxis valueAxis = plot.getRangeAxis();
    valueAxis.setLabelFont(LABEL_FONT_BOLD);
    valueAxis.setTickLabelFont(LABEL_FONT);

    return chart;
}

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYBarChart("State Executions - USA", "Year", true,
            "Number of People", intervalxydataset, PlotOrientation.VERTICAL, true, false, false);
    jfreechart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do",
            new Font("Dialog", 2, 10)));
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    StandardXYToolTipGenerator standardxytooltipgenerator = new StandardXYToolTipGenerator("{1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0"));
    xyitemrenderer.setBaseToolTipGenerator(standardxytooltipgenerator);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.white);
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    dateaxis.setLowerMargin(0.01D);//from  ww w  .jav  a 2s  .  c o m
    dateaxis.setUpperMargin(0.01D);
    return jfreechart;
}

From source file:org.gephi.ui.utils.ChartsUtils.java

/**
 * Build new Scatter plot. Appearance can be changed later with the other methods of ChartsUtils.
 * @param data Data for the plot/*w ww  . j ava 2s  .  c  o m*/
 * @param title Title for the chart
 * @param xLabel Text for x label
 * @param yLabel Text for y label
 * @param useLines Indicates if lines have to be drawn instead of shapes
 * @param useLinearRegression Indicates if the scatter plot has to have linear regreesion line drawn
 * @return Scatter plot for the data and appearance options
 */
public static JFreeChart buildScatterPlot(final XYSeriesCollection data, final String title,
        final String xLabel, final String yLabel, final boolean useLines, final boolean useLinearRegression) {
    JFreeChart scatterPlot = ChartFactory.createXYLineChart(title, xLabel, yLabel, data,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) scatterPlot.getPlot();
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainGridlinePaint(java.awt.Color.GRAY);
    plot.setRangeGridlinePaint(java.awt.Color.GRAY);

    setScatterPlotLinesEnabled(scatterPlot, useLines);
    setScatterPlotLinearRegressionEnabled(scatterPlot, useLinearRegression);
    return scatterPlot;
}

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    JFreeChart jfreechart = ChartFactory.createXYBarChart("US Budget Deficit", "Year", true, "$ Billion",
            intervalxydataset, PlotOrientation.VERTICAL, false, false, false);
    TextTitle texttitle = new TextTitle("Source: http://www.cbo.gov/showdoc.cfm?index=1821&sequence=0#table12");
    texttitle.setFont(new Font("Dialog", 0, 8));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);/*from   ww w  .  j a v a 2 s. c  o  m*/
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    StandardXYToolTipGenerator standardxytooltipgenerator = new StandardXYToolTipGenerator("{1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0"));
    xyitemrenderer.setBaseToolTipGenerator(standardxytooltipgenerator);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.white);
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    dateaxis.setLowerMargin(0.01D);
    dateaxis.setUpperMargin(0.01D);
    return jfreechart;
}

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

private static JFreeChart createChart4(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Projected Values - Test", "Date",
            "Index Projection", xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setInsets(new RectangleInsets(5D, 5D, 5D, 20D));
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    DeviationRenderer deviationrenderer = new DeviationRenderer(true, false);
    deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    deviationrenderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1));
    deviationrenderer.setSeriesFillPaint(0, new Color(255, 200, 200));
    deviationrenderer.setSeriesFillPaint(1, new Color(200, 200, 255));
    xyplot.setRenderer(deviationrenderer);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}