view flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 369:2ce7b473620e

Implemented the chart creation of a longitudinal section chart - W and Q facets. flys-artifacts/trunk@1778 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 29 Apr 2011 10:13:24 +0000
parents
children 60f63539d004
line wrap: on
line source
package de.intevation.flys.exports;

import java.awt.Color;

import java.io.IOException;

import org.apache.log4j.Logger;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYDataset;

import de.intevation.flys.exports.ChartExportHelper;


/**
 * An abstract base class for creating XY charts.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public abstract class XYChartGenerator extends ChartGenerator {

    /** The logger that is used in this generator.*/
    private static Logger logger = Logger.getLogger(ChartGenerator.class);


    /**
     * Returns the title of a chart.
     *
     * @return the title of a chart.
     */
    protected abstract String getChartTitle();

    /**
     * Returns the X-Axis label of a chart.
     *
     * @return the X-Axis label of a chart.
     */
    protected abstract String getXAxisLabel();

    /**
     * Returns the Y-Axis label of a chart.
     *
     * @return the Y-Axis label of a chart.
     */
    protected abstract String getYAxisLabel();

    /**
     * Returns the XYDataset used to add curves to the chart.
     *
     * @return the XYDataset used to add curves to the chart.
     */
    protected abstract XYDataset getXYDataset();


    public void generate()
    throws IOException
    {
        logger.debug("XYChartGenerator.generate");

        JFreeChart chart = ChartFactory.createXYLineChart(
            getChartTitle(),
            getXAxisLabel(),
            getYAxisLabel(),
            getXYDataset(),
            PlotOrientation.VERTICAL,
            true,
            false,
            false);

        chart.setBackgroundPaint(Color.WHITE);
        chart.getPlot().setBackgroundPaint(Color.WHITE);

        adjustAxes((XYPlot) chart.getPlot());

        ChartExportHelper.exportImage(
            out,
            chart,
            "png",
            600, 400);
    }


    /**
     * Adjusts the axes of a plot.
     *
     * @param plot The XYPlot of the chart.
     */
    protected void adjustAxes(XYPlot plot) {
        NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();

        yAxis.setAutoRangeIncludesZero(false);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org