diff gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java @ 846:8b6ef091d38c

It is possible to draw VerticalProfileCharts with just one single data point (issue229). gnv-artifacts/trunk@962 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 21 Apr 2010 08:46:23 +0000
parents 22c18083225e
children 38c8cc586a85
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java	Tue Apr 20 18:38:22 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java	Wed Apr 21 08:46:23 2010 +0000
@@ -17,7 +17,15 @@
 
 import org.jfree.chart.ChartTheme;
 
+import org.jfree.chart.axis.Axis;
+import org.jfree.chart.axis.AxisLocation;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.axis.NumberTickUnit;
+
 import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.chart.plot.XYPlot;
+
+import org.jfree.data.Range;
 
 import org.jfree.data.general.Series;
 
@@ -173,6 +181,45 @@
 
 
     @Override
+    protected void prepareAxis(String seriesKey,int idx) {
+        log.debug("prepare axis of xychart");
+
+        XYPlot plot      = chart.getXYPlot();
+        Axis xAxis       = plot.getDomainAxis();
+        NumberAxis yAxis = new NumberAxis(seriesKey);
+
+        localizeDomainAxis(xAxis, locale);
+        localizeRangeAxis(yAxis, locale);
+
+        // litte workarround to adjust the max range of axes.
+        // NumberAxis.setAutoRange(true) doesn't seem to work properly.
+        Range yRange = (Range) ranges.get(seriesKey);
+        yAxis.setRange(Range.expand(yRange, LOWER_MARGIN, UPPER_MARGIN));
+        log.debug("Max Range of dataset is: " + yRange.toString());
+
+        if (seriesKey.contains("richtung")) {
+            yAxis.setTickUnit(new NumberTickUnit(30.0));
+            yAxis.setUpperBound(360.0);
+            yAxis.setLowerBound(0.0);
+        }
+        else {
+            yAxis.setFixedDimension(10.0);
+            yAxis.setAutoRangeIncludesZero(false);
+        }
+
+        plot.setRangeAxis(idx, yAxis);
+        yAxis.configure();
+
+        if (idx % 2 != 0)
+            plot.setRangeAxisLocation(idx, AxisLocation.BOTTOM_OR_RIGHT);
+        else
+            plot.setRangeAxisLocation(idx, AxisLocation.BOTTOM_OR_LEFT);
+
+        plot.mapDatasetToRangeAxis(idx, idx);
+    }
+
+
+    @Override
     protected void prepareRangeAxis(String seriesKey, int idx) {
         return;
         // do nothing here

http://dive4elements.wald.intevation.org