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

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

Introduction

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

Prototype

public void setBackgroundImage(Image image) 

Source Link

Document

Sets the background image for the plot and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:no.met.jtimeseries.chart.Utility.java

/**
 * Create a plot with an error message in case of error.
 * // ww w  . j a va2 s. co m
 * @param width
 *            The width of the plot
 * @return The JFreeChart error plot
 */
public static JFreeChart createErrorChart(int width) {
    XYPlot plot = new XYPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImage(Symbols.getImage("/error.png"));
    JFreeChart jchart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    jchart.setBorderVisible(false);
    Paint paint = new GradientPaint(0, 0, Color.WHITE, width, 0, Color.WHITE);
    jchart.setBackgroundPaint(paint);

    return jchart;
}

From source file:org.openmicroscopy.shoola.util.ui.graphutils.HistogramPlot.java

/** 
 * Creates the chart./*  w ww.j  a v a 2s. c om*/
 * @see ChartObject#createChar()
 */
void createChart() {
    HistogramBarRenderer renderer = new HistogramBarRenderer(colours);
    for (int i = 0; i < colours.size(); i++)
        renderer.setSeriesPaint(i, colours.get(i));
    XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
    if (backgroundImage != null) {
        plot.setRangeGridlinesVisible(false);
        plot.setDomainGridlinesVisible(false);
        plot.setBackgroundImage(backgroundImage);
    }
    chart = new JFreeChart(title, plot);
}

From source file:org.openmicroscopy.shoola.util.ui.graphutils.ScatterPlot.java

/** 
 * Creates the chart.//from w  w  w.j  a v a  2  s.c  o m
 * @see ChartObject#createChar()
 */
void createChart() {
    PointRenderer renderer = new PointRenderer(colours, shapes);
    XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
    if (backgroundImage != null) {
        plot.setRangeGridlinesVisible(false);
        plot.setDomainGridlinesVisible(false);
        plot.setBackgroundImage(backgroundImage);
    }
    chart = new JFreeChart(title, plot);
}

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

/**
 * A demonstration application showing a quarterly time series containing a null value.
 *
 * @param title  the frame title./*from  ww w .  j  av  a  2s.c  o m*/
 */
public TimeSeriesDemo4(final String title) {

    super(title);
    final TimeSeries series = new TimeSeries("Random Data", Hour.class);
    final Day today = new Day();
    series.add(new Hour(1, today), 500.2);
    series.add(new Hour(2, today), 694.1);
    series.add(new Hour(3, today), 734.4);
    series.add(new Hour(4, today), 453.2);
    series.add(new Hour(7, today), 500.2);
    series.add(new Hour(8, today), null);
    series.add(new Hour(12, today), 734.4);
    series.add(new Hour(16, today), 453.2);
    final TimeSeriesCollection dataset = new TimeSeriesCollection(series);

    // create a title with Unicode characters (currency symbols in this case)...
    final String chartTitle = "\u20A2\u20A2\u20A3\u20A4\u20A5\u20A6\u20A7\u20A8\u20A9\u20AA";
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Time", "Value", dataset, true,
            true, false);

    final XYPlot plot = chart.getXYPlot();
    //      plot.setInsets(new Insets(0, 0, 0, 20));
    final Marker marker = new ValueMarker(700.0);
    marker.setPaint(Color.blue);
    marker.setAlpha(0.8f);
    plot.addRangeMarker(marker);
    plot.setBackgroundPaint(null);
    plot.setBackgroundImage(JFreeChart.INFO.getLogo());
    final XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer r = (StandardXYItemRenderer) renderer;
        r.setPlotShapes(true);
        r.setShapesFilled(true);
    }
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);
    setContentPane(chartPanel);

}

From source file:no.met.jtimeseries.marinogram.MarinogramWrapper.java

public JFreeChart createMarinogram(ChartPlottingInfo cpi) {
    JFreeChart jchart = null;//from w w w .  ja  v  a 2  s . c  o m
    if (!cpi.isShowAirTemperature() && !cpi.isShowWaterTemperature() && !cpi.isShowPressure()
            && !cpi.isShowWaveDirection() && !cpi.isShowWaveHeight() && !cpi.isShowCurrentDirection()
            && !cpi.isShowCurrentSpeed() && !cpi.isShowWindDirection() && !cpi.isShowWindSpeed()
            && !cpi.isShowDewpointTemperature()) {
        jchart = createEmptyChart(cpi);
        return jchart;
    }
    try {
        TimePeriod timePeriod = new TimePeriod(new Date(), MeteogramWrapper.SHORT_TERM_HOURS).adapt(3);

        // parse oceanforecast data from api.met.no
        Location location = new Location(cpi.getLongitude(), cpi.getLatitude());
        // The curve will not be shown if too many data points when setDrawSeriesLineAsPath(true) in render;
        OceanForecastParseScheme oceanForecastParseScheme = new OceanForecastParseScheme(timePeriod);
        ForecastParser forecastParser = new ForecastParser(oceanForecastParseScheme,
                OceanForecastAddressFactory.getURL(location).toString());
        // parse locationforcast data from api.met.no
        GenericDataModel locationForecastDataModel = null;
        GenericDataModel model = null;

        if (cpi.isShowAirTemperature() || cpi.isShowWaterTemperature() || cpi.isShowDewpointTemperature()) {
            MarinogramTemperaturePlot mp = new MarinogramTemperaturePlot(cpi.getWidth(), cpi.getWidth() / 4,
                    cpi.getTimezone(), cpi.getLanguage());
            totalPlotHeight += cpi.getWidth() / 4;
            mp.setDescription("Temperature Plot");
            mp.setShowAirTemp(cpi.isShowAirTemperature());
            mp.setShowSeaTemp(cpi.isShowWaterTemperature());
            mp.setShowDewTemp(cpi.isShowDewpointTemperature());
            locationForecastDataModel = MeteogramWrapper.getModel(location, timePeriod);
            mp.setLocationForecastDataModel(locationForecastDataModel);
            model = forecastParser.populateModelWithData();
            mp.setOceanForecastDataModel(model);
            this.addPlot(mp);

        }

        if (cpi.isShowCurrentDirection() || cpi.isShowCurrentSpeed()) {
            MarinogramCurrentPlot mp = new MarinogramCurrentPlot(cpi.getWidth(), cpi.getWidth() / 7,
                    cpi.getTimezone(), cpi.getLanguage());
            totalPlotHeight += cpi.getWidth() / 7;
            mp.setDescription("Current Plot");
            mp.setShowCurrentSpeed(cpi.isShowCurrentSpeed());
            mp.setShowCurrentDirection(cpi.isShowCurrentDirection());

            // extra check if model has no data
            if (model == null) {
                model = forecastParser.populateModelWithData();
            }
            mp.setOceanForecastDataModel(model);
            this.addPlot(mp);

        }

        if (cpi.isShowWaveDirection() || cpi.isShowWaveHeight()) {
            MarinogramWavePlot mp = new MarinogramWavePlot(cpi.getWidth(), cpi.getWidth() / 7,
                    cpi.getTimezone(), cpi.getLanguage());
            totalPlotHeight += cpi.getWidth() / 7;
            mp.setDescription("Wave Plot");
            mp.setShowWaveHeight(cpi.isShowWaveHeight());
            mp.setShowWaveDirection(cpi.isShowWaveDirection());

            // extra check if model has no data
            if (model == null) {
                model = forecastParser.populateModelWithData();
            }
            mp.setOceanForecastDataModel(model);
            this.addPlot(mp);

        }

        if (cpi.isShowPressure()) {
            MarinogramPressurePlot pressurePlot = new MarinogramPressurePlot(cpi.getWidth(), cpi.getWidth() / 7,
                    cpi.getTimezone(), cpi.getLanguage());
            totalPlotHeight += cpi.getWidth() / 7;
            pressurePlot.setShowPressure(cpi.isShowPressure());
            // extra check if locationForecastDataModel has no data
            if (locationForecastDataModel == null) {
                locationForecastDataModel = MeteogramWrapper.getModel(location, timePeriod);
            }
            pressurePlot.setLocationForecastDataModel(locationForecastDataModel);
            this.addPlot(pressurePlot);
        }

        if (cpi.isShowWindDirection() || cpi.isShowWindSpeed()) {
            MarinogramWindPlot mp = new MarinogramWindPlot(cpi.getWidth(), cpi.getWidth() / 7,
                    cpi.getTimezone(), cpi.getLanguage());
            totalPlotHeight += cpi.getWidth() / 7;
            mp.setDescription("Wind Plot");
            mp.setShowWindSpeed(cpi.isShowWindSpeed());
            mp.setShowWindDirection(cpi.isShowWindDirection());

            // extra check if model has no data
            if (model == null) {
                model = forecastParser.populateModelWithData();
            }
            locationForecastDataModel = MeteogramWrapper.getModel(location, timePeriod);
            mp.setLocationForecastDataModel(locationForecastDataModel);
            mp.setOceanForecastDataModel(model);
            this.addPlot(mp);

        }

        jchart = createJFreeChart("", this.getPlot(), this.getWidth());

    } catch (Exception e) {
        LogUtils.logException(logger, "Failure during marinogram generation with " + cpi.toString(), e);
        XYPlot plot = new XYPlot();
        plot.setBackgroundPaint(null);
        plot.setBackgroundImage(Symbols.getImage("/error.png"));
        jchart = createJFreeChart("", plot, this.getWidth());
    }
    return jchart;
}

From source file:lu.lippmann.cdb.ext.hydviga.data.StationsDataProvider.java

private ChartPanel buildMapPanel(final Instances dataSet, final int xidx, final int yidx,
        final boolean withLegend) {
    final XYSeriesCollection data = new XYSeriesCollection();
    final Map<Integer, java.util.List<Instance>> filteredInstances = new HashMap<Integer, java.util.List<Instance>>();
    final int classIndex = dataSet.classIndex();
    if (classIndex < 0) {
        final XYSeries series = new XYSeries("Serie", false);
        for (int i = 0; i < dataSet.numInstances(); i++) {
            series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx));
        }/*from ww  w . j  a va  2s. c  o  m*/
        data.addSeries(series);
    } else {
        final Set<String> pvs = new TreeSet<String>(
                WekaDataStatsUtil.getPresentValuesForNominalAttribute(dataSet, classIndex));
        int p = 0;
        for (final String pv : pvs) {
            final XYSeries series = new XYSeries(pv, false);
            for (int i = 0; i < dataSet.numInstances(); i++) {
                if (dataSet.instance(i).stringValue(classIndex).equals(pv)) {
                    if (!filteredInstances.containsKey(p)) {
                        filteredInstances.put(p, new ArrayList<Instance>());
                    }
                    filteredInstances.get(p).add(dataSet.instance(i));

                    series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx));
                }
            }
            data.addSeries(series);

            p++;
        }

    }

    final JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title
            dataSet.attribute(xidx).name(), // x axis label
            dataSet.attribute(yidx).name(), // y axis label
            data, // data
            PlotOrientation.VERTICAL, withLegend, // include legend
            true, // tooltips
            false // urls
    );

    final XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setBackgroundImage(shapeImage);

    final XYItemRenderer renderer = xyPlot.getRenderer();
    final XYToolTipGenerator gen = new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            if (classIndex < 0) {
                return InstanceFormatter.htmlFormat(dataSet.instance(item), true);
            } else {
                return InstanceFormatter.htmlFormat(filteredInstances.get(series).get(item), true);
            }
        }
    };

    xyPlot.getRangeAxis().setVisible(false);
    xyPlot.getDomainAxis().setVisible(false);

    xyPlot.getRangeAxis().setLowerBound(60000);
    xyPlot.getRangeAxis().setUpperBound(135000);
    xyPlot.getDomainAxis().setLowerBound(45000);
    xyPlot.getDomainAxis().setUpperBound(110000);

    xyPlot.setDomainGridlinesVisible(false);
    xyPlot.setRangeGridlinesVisible(false);

    xyPlot.setBackgroundPaint(Color.white);

    int nbSeries;
    if (classIndex < 0) {
        nbSeries = 1;
    } else {
        nbSeries = filteredInstances.keySet().size();
    }

    for (int i = 0; i < nbSeries; i++) {
        renderer.setSeriesToolTipGenerator(i, gen);
    }

    final XYItemLabelGenerator lg = new XYItemLabelGenerator() {
        @Override
        public String generateLabel(final XYDataset ds, final int series, final int item) {
            final Instance iii = filteredInstances.get(series).get(item);
            if (iii.stringValue(3).equals(SELECTED_STATUS)) {
                final String label = iii.stringValue(0);
                return label.substring(0, label.length() - 4);
            } else
                return null;
        }
    };
    xyPlot.getRenderer().setBaseItemLabelGenerator(lg);
    xyPlot.getRenderer().setBaseItemLabelsVisible(true);
    xyPlot.getRenderer().setBaseItemLabelFont(new Font("Tahoma", Font.PLAIN, 12));

    xyPlot.getRenderer().setSeriesPaint(1, Color.BLUE);
    xyPlot.getRenderer().setSeriesPaint(0, new Color(210, 210, 210));
    xyPlot.getRenderer().setSeriesPaint(2, Color.DARK_GRAY);

    //System.out.println("shape -> "+xyPlot.getRenderer().getSeriesStroke(0));

    final ChartPanel cp = new ChartPanel(chart);
    cp.setDomainZoomable(false);
    cp.setRangeZoomable(false);

    return cp;
}

From source file:org.ramadda.data.services.PointFormHandler.java

/**
 * create jfree chart/*from  www. j  av a 2  s .c o  m*/
 *
 * @param request the request
 * @param entry The entry
 * @param dataset the dataset
 * @param backgroundImage background image
 *
 * @return the chart
 */
public static JFreeChart createTimeseriesChart(Request request, Entry entry, XYDataset dataset,
        Image backgroundImage) {
    JFreeChart chart = ChartFactory.createXYLineChart("", // chart title
            "", // x axis label
            "Height", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    DateAxis timeAxis = new DateAxis("Time", request.getRepository().TIMEZONE_UTC);
    NumberAxis valueAxis = new NumberAxis("Data");
    valueAxis.setAutoRangeIncludesZero(true);

    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);

    chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(Color.white);
    if (backgroundImage != null) {
        plot.setBackgroundImage(backgroundImage);
        plot.setBackgroundImageAlignment(org.jfree.ui.Align.TOP_LEFT);
    }

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setInsets(new RectangleInsets(0, 0, 0, 0));
    plot.setAxisOffset(new RectangleInsets(5, 0, 5, 0));

    return chart;
}

From source file:org.gvsig.gui.beans.graphic.GraphicChartPanel.java

/**
 * Creates a chart./*from   w w w  .j av  a 2s.c om*/
 * @param dataset the dataset.
 * @return A chart.
 */
private void createChart() {
    chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL, false, true,
            true);

    // Definir la lista de colores
    XYPlot plot = chart.getXYPlot();
    plot.getRenderer().setSeriesPaint(0, Color.red);
    plot.getRenderer().setSeriesPaint(1, Color.green);
    plot.getRenderer().setSeriesPaint(2, Color.blue);
    plot.getRenderer().setSeriesPaint(3, Color.cyan);
    plot.getRenderer().setSeriesPaint(4, Color.black);
    plot.getRenderer().setSeriesPaint(5, Color.darkGray);
    plot.getRenderer().setSeriesPaint(6, Color.gray);
    plot.getRenderer().setSeriesPaint(7, Color.magenta);
    plot.getRenderer().setSeriesPaint(8, Color.yellow);
    plot.getRenderer().setSeriesPaint(9, Color.orange);

    Image img = new ImageIcon(getClass().getResource("images/splash.png")).getImage();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImageAlpha(0.18f);
    plot.setBackgroundImage(img);
}

From source file:pipeline.parameter_cell_views.FloatRangeSlider.java

@Override
protected Component getRendererOrEditorComponent(JTable table0, @NonNull Object value, boolean isSelected,
        boolean hasFocus, int row, int column, boolean rendererCalled) {
    if (currentParameter != null) {
        currentParameter.removeListener(this);
    }/*from   w  w w. ja v  a 2s  .c  om*/

    currentParameter = (FloatRangeParameter) value;
    currentParameter.addGUIListener(this);

    table = table0;
    tableRow = row;

    evenTableRow = (row % 2 == 0);
    setOpaque(true);
    if (evenTableRow) {
        this.setBackground(Utils.COLOR_FOR_EVEN_ROWS);
    } else
        this.setBackground(Utils.COLOR_FOR_ODD_ROWS);
    textValueFrame.setBackground(getBackground());

    silenceUpdate = true;

    readInValuesFromParameter();

    if (currentParameter.histogram == null)
        ;// currentParameter.histogram=new XYSeries("");

    if (currentParameter.histogram instanceof XYSeries) {

        XYSeries xyData = (XYSeries) currentParameter.histogram;

        if (chart != null && chart.getXYPlot().getDataset() != null) {
            chart.getXYPlot().getDataset(0).removeChangeListener(chart.getXYPlot());
        }

        chart = ChartFactory.createXYLineChart(null, // chart title
                null, // "Category", // domain axis label
                null, // "Value", // range axis label
                new XYSeriesCollection(xyData), // data
                PlotOrientation.VERTICAL, false, // include legend
                true, false);

    } else if (currentParameter.histogram != null) { // assume for now it's a histogram
        if (chart != null && chart.getXYPlot().getDataset() != null) {
            chart.getXYPlot().getDataset(0).removeChangeListener(chart.getXYPlot());
        }

        String plotTitle = "Histogram";
        String xaxis = "number";
        String yaxis = "value";
        PlotOrientation orientation = PlotOrientation.VERTICAL;
        boolean show = false;
        boolean toolTips = false;
        boolean urls = false;
        chart = ChartFactory.createHistogram(plotTitle, xaxis, yaxis,
                (IntervalXYDataset) currentParameter.histogram, orientation, show, toolTips, urls);// dataset
    } else {
        if (chart != null && chart.getXYPlot().getDataset() != null) {
            chart.getXYPlot().getDataset(0).removeChangeListener(chart.getXYPlot());
        }
        chart = null;
    }

    if (currentParameter.histogram != null) {
        add(panelForHistogram, cForHistogram);
        final XYPlot plot = chart.getXYPlot();
        final NumberAxis domainAxis = new NumberAxis(null);
        domainAxis.setAutoRange(false);
        domainAxis.setTickLabelFont(new Font("Times", 0, 20));
        domainAxis.setLowerBound(minimum);
        domainAxis.setUpperBound(maximum);
        plot.setDomainAxis(domainAxis);

        final NumberAxis rangeAxis = new NumberAxis(null);
        rangeAxis.setAutoRange(true);
        rangeAxis.setVisible(false);
        plot.setRangeAxis(rangeAxis);
        chart.setBackgroundPaint(Color.white);
        chart.setPadding(new RectangleInsets(0, 0, 0, 0));

        plot.setBackgroundImage(null);
        plot.setBackgroundPaint(Color.white);
        plot.setOutlinePaint(Color.black);

        if (chartPanel == null) {
            chartPanel = new ChartPanel(chart);
            chartPanel.addMouseListener(this);
            chartPanel.addMouseMotionListener(this);
            chartPanel.setMouseWheelEnabled(true);
            chartPanel.setMouseZoomable(false);
            chartPanel.setRangeZoomable(false);

            panelForHistogram.add(chartPanel);

        } else
            chartPanel.setChart(chart);

        chartPanel.setSize(panelForHistogram.getSize());

        ((XYPlot) chart.getPlot()).getRenderer().setSeriesStroke(0, new BasicStroke(5.0f));
        selectionRange = new IntervalMarker(currentValue0, currentValue1);
        ((XYPlot) chart.getPlot()).addDomainMarker(selectionRange);
    } else {
        remove(panelForHistogram);
        setMaximumSize(new Dimension(700, 50));
        setPreferredSize(new Dimension(700, 50));
    }

    updateDisplays();

    silenceUpdate = false;
    return this;
}