Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
368:3e66a5705c39 | 369:2ce7b473620e |
---|---|
1 package de.intevation.flys.exports; | |
2 | |
3 import java.awt.Color; | |
4 | |
5 import java.io.IOException; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 | |
9 import org.jfree.chart.ChartFactory; | |
10 import org.jfree.chart.JFreeChart; | |
11 import org.jfree.chart.axis.NumberAxis; | |
12 import org.jfree.chart.plot.PlotOrientation; | |
13 import org.jfree.chart.plot.XYPlot; | |
14 import org.jfree.data.xy.XYDataset; | |
15 | |
16 import de.intevation.flys.exports.ChartExportHelper; | |
17 | |
18 | |
19 /** | |
20 * An abstract base class for creating XY charts. | |
21 * | |
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
23 */ | |
24 public abstract class XYChartGenerator extends ChartGenerator { | |
25 | |
26 /** The logger that is used in this generator.*/ | |
27 private static Logger logger = Logger.getLogger(ChartGenerator.class); | |
28 | |
29 | |
30 /** | |
31 * Returns the title of a chart. | |
32 * | |
33 * @return the title of a chart. | |
34 */ | |
35 protected abstract String getChartTitle(); | |
36 | |
37 /** | |
38 * Returns the X-Axis label of a chart. | |
39 * | |
40 * @return the X-Axis label of a chart. | |
41 */ | |
42 protected abstract String getXAxisLabel(); | |
43 | |
44 /** | |
45 * Returns the Y-Axis label of a chart. | |
46 * | |
47 * @return the Y-Axis label of a chart. | |
48 */ | |
49 protected abstract String getYAxisLabel(); | |
50 | |
51 /** | |
52 * Returns the XYDataset used to add curves to the chart. | |
53 * | |
54 * @return the XYDataset used to add curves to the chart. | |
55 */ | |
56 protected abstract XYDataset getXYDataset(); | |
57 | |
58 | |
59 public void generate() | |
60 throws IOException | |
61 { | |
62 logger.debug("XYChartGenerator.generate"); | |
63 | |
64 JFreeChart chart = ChartFactory.createXYLineChart( | |
65 getChartTitle(), | |
66 getXAxisLabel(), | |
67 getYAxisLabel(), | |
68 getXYDataset(), | |
69 PlotOrientation.VERTICAL, | |
70 true, | |
71 false, | |
72 false); | |
73 | |
74 chart.setBackgroundPaint(Color.WHITE); | |
75 chart.getPlot().setBackgroundPaint(Color.WHITE); | |
76 | |
77 adjustAxes((XYPlot) chart.getPlot()); | |
78 | |
79 ChartExportHelper.exportImage( | |
80 out, | |
81 chart, | |
82 "png", | |
83 600, 400); | |
84 } | |
85 | |
86 | |
87 /** | |
88 * Adjusts the axes of a plot. | |
89 * | |
90 * @param plot The XYPlot of the chart. | |
91 */ | |
92 protected void adjustAxes(XYPlot plot) { | |
93 NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); | |
94 | |
95 yAxis.setAutoRangeIncludesZero(false); | |
96 } | |
97 } | |
98 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |