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:ac.kaist.ccs.presentation.CCSHubSelectionCo2Coverage.java

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

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            "Number of Hubs", // x axis label
            "Percent of CO2 emission amount coverage (%)", // y axis label
            dataset, // 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.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    //renderer.setSeriesLinesVisible(0, false);
    //renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

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

    return chart;

}

From source file:gov.sandia.umf.platform.ui.jobs.Raster.java

public JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );/*from ww w.jav a  2  s.  co  m*/

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setDomainPannable(true);
    plot.setRangePannable(true);

    plot.setRenderer(new XYDotRenderer() {
        public void drawItem(java.awt.Graphics2D g2, XYItemRendererState state,
                java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis,
                ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState,
                int pass) {
            // Copied from org.jfree.chart.renderer.xy.XYDotRenderer.java and modified.
            // This would only need to be a couple of lines if they authors of jfreechart had not made dotWidth and dotHeight private members.
            // Yet another example of textbook OO programming gone awry. (Can anyone hear me scream?)

            if (!getItemVisible(series, item))
                return;

            int dotWidth = 1;

            double rasterLines = rangeAxis.getRange().getLength();
            int pixels = g2.getClipBounds().height;
            double height = pixels / rasterLines;
            if (height > 10)
                height -= 2;
            else if (height > 2)
                height -= 1;
            int dotHeight = (int) Math.min(20, Math.max(1, Math.floor(height)));

            double x = dataset.getXValue(series, item);
            double y = dataset.getYValue(series, item);
            if (Double.isNaN(y))
                return;
            double adjx = (dotWidth - 1) / 2.0;
            double adjy = (dotHeight - 1) / 2.0;

            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
            double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
            double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;

            g2.setPaint(Color.black);
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL)
                g2.fillRect((int) transY, (int) transX, dotHeight, dotWidth);
            else
                g2.fillRect((int) transX, (int) transY, dotWidth, dotHeight);

            int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
            int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
            updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                    orientation);
        }
    });

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Integer units only

    return chart;
}

From source file:domain.Grafica.java

public JFreeChart createChart(XYDataset dataset) {
    /*/*from   ww w .ja  va 2 s . c o m*/
     ///*
     NumberAxis numberaxis = new NumberAxis("");
     numberaxis.setAutoRangeIncludesZero(false);
            
     DateAxis dateaxis = new DateAxis("");
            
     NumberAxis numberaxis1 = new NumberAxis("");
     numberaxis1.setAutoRangeIncludesZero(false);
            
     XYSplineRenderer xysplinerenderer = new XYSplineRenderer();
            
     XYPlot xyplot = new XYPlot(dataset, dateaxis, numberaxis1, xysplinerenderer);
     // xyplot.setBackgroundPaint(new Color(238, 242, 250));//
     // xyplot.setDomainGridlinePaint(new Color(255, 255, 255));
     // xyplot.setRangeGridlinePaint(new Color(238, 242, 250));
     xyplot.getRenderer().setSeriesPaint(0, Color.RED);
     xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
     XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
     renderer.setSeriesShapesVisible(0, true);//FIXME Dots
            
     //  xyplot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
     JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, xyplot, false);
     jfreechart.setBackgroundPaint(Color.white);
            
     DateAxis axis = (DateAxis) xyplot.getDomainAxis();
     axis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa"));
            
     xyplot.getRangeAxis().setUpperBound(maxPeso * 1.25);
     xyplot.getRangeAxis().setLowerBound(minPeso * 0.75);
     cargarImagen();
     // xyplot.setBackgroundImage(i);
     //jfreechart.setBackgroundImage(i);
     return jfreechart;
     */
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", // title
            "Fecha/Hora", // x-axis label
            "Pesos(Kg.)", // y-axis label
            dataset, // data
            false, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.GRAY);
    plot.setRangeGridlinePaint(Color.GRAY);
    /*         plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
     plot.setDomainCrosshairVisible(false);
     plot.setRangeCrosshairVisible(false);
     */
    plot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

    XYItemRenderer r = plot.getRenderer();

    if (r instanceof XYLineAndShapeRenderer) {

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
    }

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    // range.setAutoRangeIncludesZero(true);
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss"));

    plot.getRangeAxis().setUpperBound(maxPeso * 1.25);
    plot.getRangeAxis().setLowerBound(minPeso * 0.75);

    return chart;

}

From source file:org.rioproject.examples.hospital.ui.PatientStatsPanel.java

private JFreeChart createTimeSeriesChart(TimeSeriesCollection dataSet, Color color) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataSet, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getRenderer().setSeriesPaint(0, color);
    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);

    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setRange(0, 150);/*  w w  w .j  a  v  a 2s  .  c  om*/
    ValueAxis xAxis = plot.getDomainAxis();
    xAxis.setAutoRange(true);
    xAxis.setFixedAutoRange(5 * MINUTE);
    return chart;
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createPlainHistoryChart(IntervalXYDataset dataset,
        XYItemLabelGenerator labelGenerator) {
    if (dataset == null) {
        throw new IllegalArgumentException("No dataset.");
    }/*  w  w w . j a v a2 s . co m*/

    JFreeChart jfreechart = ChartFactory.createXYBarChart(null, null, true, null, dataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(null);
    xyplot.setOutlinePaint(null);
    XYBarRenderer renderer = (XYBarRenderer) xyplot.getRenderer();
    renderer.setShadowVisible(false);
    renderer.setBaseItemLabelsVisible(true);
    if (labelGenerator != null) {
        renderer.setBaseItemLabelGenerator(labelGenerator);
    }
    renderer.setBaseItemLabelFont(UIConstants.H4_FONT);
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setSeriesPaint(0, UIConstants.INTEL_BLUE);
    // xyplot.getDomainAxis().setVisible(false);
    xyplot.getDomainAxis().setAxisLineVisible(true);
    xyplot.getDomainAxis().setTickLabelsVisible(false);
    NumberAxis axis = (NumberAxis) xyplot.getRangeAxis();
    axis.setRangeType(RangeType.POSITIVE);
    axis.setVisible(false);
    return jfreechart;
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createXYBarChart(String xAxisLabel, String yAxisLabel, IntervalXYDataset dataset,
        XYItemLabelGenerator labelGenerator) {
    if (dataset == null) {
        throw new IllegalArgumentException("No dataset.");
    }//  ww w  .  j  a v  a  2s .  c  o  m

    JFreeChart jfreechart = ChartFactory.createXYBarChart(null, xAxisLabel, false, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(null);
    xyplot.setOutlinePaint(null);
    xyplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY);

    NumberAxis axis = (NumberAxis) xyplot.getRangeAxis();
    axis.setRangeType(RangeType.POSITIVE);
    axis.setLabelFont(UIConstants.H5_FONT);
    xyplot.getDomainAxis().setLabelFont(UIConstants.H5_FONT);
    XYBarRenderer renderer = (XYBarRenderer) xyplot.getRenderer();
    renderer.setShadowVisible(false);
    renderer.setBaseItemLabelsVisible(true);
    if (labelGenerator != null) {
        renderer.setBaseItemLabelGenerator(labelGenerator);
    }
    renderer.setBaseItemLabelFont(UIConstants.H5_FONT);
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setSeriesPaint(0, UIConstants.INTEL_BLUE);
    return jfreechart;
}

From source file:net.pickapack.chart.LinePlotFrame.java

/**
 * Create a line plot frame.//from   w  w  w .  j av a2 s.com
 *
 * @param linePlot the line plot
 * @param width the width
 * @param height the height
 */
public LinePlotFrame(LinePlot linePlot, int width, int height) {
    super(linePlot.getTitle());
    this.linePlot = linePlot;

    this.numSubPlots = linePlot.getSubLinePlots().size();

    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.dataSets = new ArrayList<TimeSeriesCollection>();
    this.dataSinks = new ArrayList<Map<SubLinePlotLine, Function<Double>>>();

    for (SubLinePlot subLinePlot : linePlot.getSubLinePlots()) {
        TimeSeriesCollection dataSetsPerSubPlot = new TimeSeriesCollection();
        this.dataSets.add(dataSetsPerSubPlot);

        HashMap<SubLinePlotLine, Function<Double>> dataSinksPerSubPlot = new HashMap<SubLinePlotLine, Function<Double>>();
        this.dataSinks.add(dataSinksPerSubPlot);

        for (SubLinePlotLine subLinePlotLine : subLinePlot.getLines()) {
            TimeSeries timeSeries = new TimeSeries(subLinePlotLine.getTitle());
            dataSetsPerSubPlot.addSeries(timeSeries);
            dataSinksPerSubPlot.put(subLinePlotLine, subLinePlotLine.getGetValueCallback());
        }

        NumberAxis rangeAxis = new NumberAxis(subLinePlot.getTitleY());
        rangeAxis.setAutoRangeIncludesZero(false);
        XYPlot subplot = new XYPlot(dataSetsPerSubPlot, null, rangeAxis, new StandardXYItemRenderer());
        subplot.setBackgroundPaint(Color.lightGray);
        subplot.setDomainGridlinePaint(Color.white);
        subplot.setRangeGridlinePaint(Color.white);
        plot.add(subplot);
    }

    JFreeChart chart = new JFreeChart(linePlot.getTitle(), plot);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(3600000.0);

    JPanel content = new JPanel(new BorderLayout());

    ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);

    DataSink dataSink = new DataSink();
    new Thread(dataSink).start();
}

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

/**
 * Creates the demo chart.//from  w  ww  .j a v  a2 s.  c  o m
 * 
 * @return The chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart1 = ChartFactory.createTimeSeriesChart(chartTitle, domainLabel, //"Time of Day", 
            rangeLabel, //"Value",
            dataset, !legendPanelOn, true, false);

    chart1.setBackgroundPaint(Color.white);
    XYPlot plot = chart1.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    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.setDomainCrosshairLockedOnData(false);
    plot.setRangeCrosshairVisible(false);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBasePaint(Color.black);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    //         setXSummary(dataset); X is time
    return chart1;
}

From source file:ec.ui.view.ARPView.java

@Override
protected void onColorSchemeChange() {
    XYPlot plot = getPlot();
    plot.setBackgroundPaint(themeSupport.getPlotColor());
    plot.setDomainGridlinePaint(themeSupport.getGridColor());
    plot.setRangeGridlinePaint(themeSupport.getGridColor());
    chartPanel.getChart().setBackgroundPaint(themeSupport.getBackColor());

    plot.getRenderer().setBasePaint(themeSupport.getLineColor(KnownColor.BROWN));

    List<Marker> markers = new ArrayList<>();
    Collection rm = plot.getRangeMarkers(Layer.FOREGROUND);
    if (rm != null) {
        markers.addAll(rm);//from   w ww .j  a v a 2  s. com
    }
    Collection dm = plot.getDomainMarkers(Layer.FOREGROUND);
    if (dm != null) {
        markers.addAll(dm);
    }
    for (Marker o : markers) {
        if (o instanceof ExtValueMarker) {
            ((ExtValueMarker) o).applyColorScheme(themeSupport);
        }
    }
}

From source file:ec.nbdemetra.ui.chart3d.functions.Functions2DChart.java

@Override
protected void onColorSchemeChange() {
    functionRenderer.setBasePaint(themeSupport.getLineColor(ColorScheme.KnownColor.BLUE));
    optimumRenderer.setBasePaint(themeSupport.getLineColor(KnownColor.RED));

    XYPlot mainPlot = chart.getXYPlot();
    mainPlot.setBackgroundPaint(themeSupport.getPlotColor());
    mainPlot.setDomainGridlinePaint(themeSupport.getGridColor());
    mainPlot.setRangeGridlinePaint(themeSupport.getGridColor());
    chart.setBackgroundPaint(themeSupport.getBackColor());
}