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:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createStepAreaChart(XYDataset dataset, XYItemLabelGenerator labelGenerator) {
    if (dataset == null) {
        throw new IllegalArgumentException("No dataset.");
    }// w ww . j  a  v  a2  s  . com

    JFreeChart jfreechart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
            false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(UIConstants.INTEL_BACKGROUND_GRAY);
    // xyplot.setOutlinePaint(null);
    XYStepAreaRenderer xysteparearenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA) {

        @Override
        public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea,
                PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis,
                XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
            setShapesVisible(item == dataset.getItemCount(series) - 1);
            super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                    crosshairState, pass);
        }

    };
    xysteparearenderer.setDataBoundsIncludesVisibleSeriesOnly(false);
    xysteparearenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xysteparearenderer.setDefaultEntityRadius(6);
    xysteparearenderer.setShapesFilled(true);
    xyplot.setRenderer(xysteparearenderer);

    if (labelGenerator != null) {
        xysteparearenderer.setBaseItemLabelGenerator(labelGenerator);
    }
    xysteparearenderer.setSeriesPaint(0, UIConstants.INTEL_GREEN);
    xyplot.setOutlinePaint(UIConstants.INTEL_DARK_GRAY);
    xyplot.setDomainGridlinePaint(UIConstants.INTEL_DARK_GRAY);
    xyplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY);

    xyplot.getDomainAxis().setVisible(false);

    NumberAxis axis = (NumberAxis) xyplot.getRangeAxis();
    axis.setRangeType(RangeType.POSITIVE);
    axis.setAxisLineVisible(false);

    return jfreechart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.IndexChart.java

/**
 * Creates a chart./*from   www  .  j a v a  2 s. c o m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    //   create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            domainLabel, // x axis label 
            rangeLabel, // y axis label  
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();

    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    //  renderer.setSeriesShape(0, java.awt.Shape.round);
    renderer.setBaseShapesVisible(false);
    renderer.setBaseShapesFilled(false);
    renderer.setBaseLinesVisible(true);

    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    //change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0.05);
    rangeAxis.setLowerMargin(0.05);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(false);
    //  domainAxis.setTickLabelsVisible(false);
    // domainAxis.setTickMarksVisible(false);      
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);

    // OPTIONAL CUSTOMISATION COMPLETED.
    setYSummary(dataset);

    return chart;
}

From source file:flexflux.analyses.result.ParetoAnalysisResult.java

public void plot() {

    XYSeriesCollection dataset = new XYSeriesCollection();

    int i = 1;//from   w  ww  .j  a va  2  s. c om
    for (Objective obj : oneDResults.keySet()) {

        XYSeries series = new XYSeries(obj.getName());

        for (double val : oneDResults.get(obj)) {

            series.add(i, val);
        }

        dataset.addSeries(series);
        i++;
    }

    // create the chart...

    final JFreeChart chart = ChartFactory.createXYLineChart("", // chart title
            "Objectives", // x axis label
            "Values", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    ChartPanel chartPanel = new ChartPanel(chart);

    XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setDomainGridlinePaint(Color.GRAY);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(false);
    renderer.setShapesVisible(true);
    plot.setRenderer(renderer);

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

    JFrame frame = new JFrame("Pareto analysis one dimension results");
    frame.add(chartPanel);

    frame.pack();

    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setVisible(true);

    for (PP2DResult r : twoDResults.keySet()) {

        r.plot();

    }

    for (PP3DResult r : threeDResults.keySet()) {

        r.plot();

    }

}

From source file:com.bitplan.vzjava.Plot.java

/**
 * Creates a chart.//www.  ja va 2s.c  o m
 * 
 * @param dataset
 *          a dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final ColoredDataSet cdataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, "Time", "Power", cdataset.dataSet, true,
            true, false);

    chart.setBackgroundPaint(Color.white);

    // final StandardLegend sl = (StandardLegend) chart.getLegend();
    // sl.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    // plot.setOutlinePaint(null);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(false);

    final XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        renderer.setSeriesStroke(0, new BasicStroke(3.0f));
        renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    }

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

    // http://www.jfree.org/jfreechart/api/gjdoc/org/jfree/chart/plot/DefaultDrawingSupplier-source.html
    DrawingSupplier supplier = new DefaultDrawingSupplier(cdataset.paintSequence,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
    chart.getPlot().setDrawingSupplier(supplier);
    return chart;
}

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

/**
 * Creates the demo chart./*from w  ww. j  av  a  2s .  co m*/
 * 
 * @return The chart.
 */
private JFreeChart createChart() {

    final XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200);

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 1", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    chart.addSubtitle(new TextTitle("Four datasets and four range axes."));
    final XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPaint(Color.black);

    // AXIS 2
    final NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    final XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    final NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    plot.setRangeAxis(2, axis3);

    final XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4        
    final NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    final XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}

From source file:org.jcryptool.visual.verifiablesecretsharing.views.ReconstructionChartComposite.java

/**
 * Creates a chart.//w  w  w. j a  v  a2  s .c om
 *
 * @param dataset
 *            the data for the chart.
 *
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...

    final JFreeChart chart = ChartFactory.createXYLineChart("", // chart
            // title
            "", // x axis label
            "", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            false, // tooltips
            false // urls
    );
    // XYSplineRenderer -- show data points
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    // show no line
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesLinesVisible(3, false);
    // show no points
    renderer.setSeriesShapesVisible(1, false);

    // set range of axis
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(-0.1, playerID[playerID.length - 1] + 0.1);
    domain.setTickUnit(new NumberTickUnit(1));
    domain.setVerticalTickLabels(false);

    // display value
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(0);
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator(
            StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format);
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelsVisible(true);

    plot.setRenderer(renderer);

    return chart;

}

From source file:controletanquesproj1.Grafico.java

/**
 * Creates a chart./*  w  w w  .j  a  v  a  2  s  .  c o m*/
 * 
 * @param _datasets
 * @param datasets
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
public JFreeChart createChart() {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("", // chart title
            "Amostra", // x axis label
            "Amplitude (V)", // y axis label
            getDatasets()[0], // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.getRangeAxis(0).setRange(-30, 30);

    final NumberAxis axis2 = new NumberAxis("Altura (cm)");
    axis2.setAutoRange(true);
    axis2.setAutoRangeIncludesZero(false);

    //axis2.setRange(-4.9, 34.9);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, getDatasets()[1]);
    plot.mapDatasetToRangeAxis(1, 1);

    /*
    getRenderer().setSeriesLinesVisible(0, true);
    getRenderer().setSeriesShapesVisible(0, false);
    getRenderer().setSeriesShapesVisible(1, false);
    getRenderer().setSeriesShapesVisible(2, false);
    getRenderer().setSeriesLinesVisible(3, true);
    getRenderer().setSeriesShapesVisible(3, false);
    */

    renderer[0].setBaseShapesVisible(false);
    renderer[0].setAutoPopulateSeriesPaint(true);

    plot.setRenderer(renderer[0]);

    renderer[1] = new XYLineAndShapeRenderer();
    renderer[1].setBaseLinesVisible(true);
    renderer[1].setBaseShapesVisible(true);

    plot.setRenderer(1, renderer[1]);

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

    return chart;

}

From source file:regression.gui.RegressionChart.java

/**
 * Creates a chart./*from w  ww.ja  va 2  s. c o  m*/
 *
 * @param dataset the data for the chart.
 *
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createScatterPlot("Wykres funkcji regresji", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesShape(0, ShapeUtilities.createRegularCross(3, 3));
    renderer.setSeriesShape(2, ShapeUtilities.createRegularCross(3, 3));
    renderer.setSeriesLinesVisible(0, false);

    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesLinesVisible(2, false);
    plot.setRenderer(renderer);

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

    return chart;

}

From source file:com.itemanalysis.jmetrik.graph.histogram.HistogramPanel.java

public void setGraph() {
    HistogramChartDataset dataset = null;
    dataset = new HistogramChartDataset();

    chart = HistogramChart.createHistogram(chartTitle, xlabel, //x-axis label
            ylabel, //y-axis label
            dataset, chartOrientation, hasGroupingVariable, //legend
            true, //tooltips
            false //urls
    );//from w  w w .  j  a v a 2s.c om

    if (chartSubtitle != null && !"".equals(chartSubtitle)) {
        TextTitle subtitle1 = new TextTitle();
        chart.addSubtitle(subtitle1);
    }

    XYPlot plot = (XYPlot) chart.getPlot();
    if (hasGroupingVariable)
        plot.setForegroundAlpha(0.80f);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);

    //next two lines are temp setting for book
    //these two lines will create a histogram with white bars so it appears as just the bar outline
    //        renderer.setBarPainter(new StandardXYBarPainter());
    //        renderer.setSeriesPaint(0, Color.white);

    ChartPanel panel = new ChartPanel(chart);
    panel.getPopupMenu().addSeparator();
    this.addJpgMenuItem(this, panel.getPopupMenu());
    panel.setPreferredSize(new Dimension(width, height));

    //        //temp setting for book
    //        this.addLocalEPSMenuItem(this, panel.getPopupMenu(), chart);//remove this line for public release versions

    chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0));
    this.setBackground(Color.WHITE);
    this.add(panel);

}

From source file:com.joey.software.memoryToolkit.MemoryUsagePanel.java

/**
 * Creates a new application./*from  w ww .  ja v  a2  s .  c o m*/
 * 
 * @param historyCount
 *            the history count (in milliseconds).
 */
public MemoryUsagePanel(int historyCount, int interval) {
    super(new BorderLayout());
    // create two series that automatically discard data more than 30
    // seconds old...
    this.total = new TimeSeries("Total Memory", Millisecond.class);
    this.total.setMaximumItemCount(historyCount);
    this.free = new TimeSeries("Free Memory", Millisecond.class);
    this.free.setMaximumItemCount(historyCount);
    this.used = new TimeSeries("Used Memory", Millisecond.class);
    this.used.setMaximumItemCount(historyCount);
    this.max = new TimeSeries("Used Memory", Millisecond.class);
    this.max.setMaximumItemCount(historyCount);
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(this.total);
    dataset.addSeries(this.free);
    dataset.addSeries(this.used);
    dataset.addSeries(this.max);

    DateAxis domain = new DateAxis("Time");
    NumberAxis range = new NumberAxis("Memory");

    domain.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    range.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    domain.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));

    range.setLabelFont(new Font("SansSerif", Font.PLAIN, 14));
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setSeriesPaint(0, Color.red);
    renderer.setSeriesPaint(1, Color.green);
    renderer.setSeriesPaint(2, Color.black);

    renderer.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    XYPlot plot = new XYPlot(dataset, domain, range, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    domain.setAutoRange(true);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setTickLabelsVisible(true);
    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    JFreeChart chart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", Font.BOLD, 24), plot, true);
    chart.setBackgroundPaint(Color.white);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(Color.black)));
    add(chartPanel);

    gen = new DataGenerator(interval);

}