diff gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractHistogram.java @ 617:3d13fa281a7e

Added new ouput mode: histogram. gnv-artifacts/trunk@688 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 15 Feb 2010 11:44:01 +0000
parents
children 65f09139e9b3
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractHistogram.java	Mon Feb 15 11:44:01 2010 +0000
@@ -0,0 +1,79 @@
+package de.intevation.gnv.chart;
+
+import java.util.Locale;
+
+import org.apache.log4j.Logger;
+
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.ChartTheme;
+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.chart.renderer.xy.XYBarRenderer;
+
+import org.jfree.data.statistics.HistogramDataset;
+
+
+/**
+ * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
+ */
+public abstract class AbstractHistogram
+implements            Chart
+{
+    private Logger logger = Logger.getLogger(AbstractHistogram.class);
+
+    protected JFreeChart  chart;
+    protected ChartLabels labels;
+    protected ChartTheme  theme;
+    protected Object[]    data;
+
+    protected Locale     locale;
+
+
+    public AbstractHistogram(
+        ChartLabels labels, Object[] data, ChartTheme theme
+    ) {
+        this.labels = labels;
+        this.data   = data;
+        this.theme  = theme;
+    }
+
+
+    public JFreeChart generateChart() {
+
+        if (chart != null)
+            return chart;
+
+        chart = ChartFactory.createHistogram(
+            labels.getTitle(),
+            labels.getDomainAxisLabel(),
+            labels.getRangeAxisLabel(),
+            null,
+            PlotOrientation.VERTICAL,
+            true,
+            false,
+            false);
+
+        applyDatasets();
+
+        theme.apply(chart);
+        adjustPlot();
+
+        return chart;
+    }
+
+
+    protected void adjustPlot() {
+        XYPlot plot = (XYPlot) chart.getPlot();
+        XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
+
+        renderer.setShadowVisible(false);
+        renderer.setSeriesVisibleInLegend(0, false);
+    }
+
+
+    protected abstract void applyDatasets();
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org