Example usage for org.jfree.chart.annotations XYImageAnnotation XYImageAnnotation

List of usage examples for org.jfree.chart.annotations XYImageAnnotation XYImageAnnotation

Introduction

In this page you can find the example usage for org.jfree.chart.annotations XYImageAnnotation XYImageAnnotation.

Prototype

public XYImageAnnotation(double x, double y, Image image, RectangleAnchor anchor) 

Source Link

Document

Creates a new annotation to be displayed at the specified (x, y) location.

Usage

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

/**
 * Adds the specified weather symbols to the chart. Symbols are excluded if
 * necessary to fit in the chart. Specify phenomenon to follow value curve.
 * Plot on top of chart if phenomenon is null.
 * /*from  www. ja v a 2 s.  c om*/
 * @return
 */
public void addWeatherSymbol(SymbolPhenomenon symbols, NumberPhenomenon phenomenon) {

    boolean followPhenomenon = (phenomenon != null);
    NumberAxis na;
    if (!followPhenomenon) {
        na = new NumberAxis("");
        na.setVisible(false);
        weatherSymbolPlot = new XYPlot();
        weatherSymbolPlot.setDomainAxis(plot.getDomainAxis(0));
        weatherSymbolPlot.setRangeAxis(na);
        weatherSymbolPlot.setRangeGridlinesVisible(false);
        weatherSymbolPlot.setOutlineVisible(false);
        weatherSymbolPlot.setDomainGridlinesVisible(false);
    }

    XYImageAnnotation imageannotation;

    int imageSize = getWeatherSymbolImageSize();

    for (SymbolValueItem symbol : symbols) {
        Image image = Symbols.getSymbolImage(symbol.getValue());
        image = image.getScaledInstance(imageSize, imageSize, Image.SCALE_SMOOTH);
        if (followPhenomenon) { // plot over the phenomenon curve
            Double val = phenomenon.getValueByTime(symbol.getTimeFrom());
            if (val != null) {
                double padding = 0.08; // space between curve and symbol in
                                       // phenomenon units
                imageannotation = new XYImageAnnotation(symbol.getTimeFrom().getTime(),
                        val.doubleValue() + padding
                                * (plot.getRangeAxis().getUpperBound() - plot.getRangeAxis().getLowerBound()),
                        image, RectangleAnchor.CENTER);
                plot.addAnnotation(imageannotation);
            }
        } else { // plot symbols on top in separate weatherSymbolPlot
            imageannotation = new XYImageAnnotation(symbol.getTimeFrom().getTime(), 0.5, image);
            weatherSymbolPlot.addAnnotation(imageannotation);
        }
    }
}