comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 419:4de7d9eac10f

Display gridlines in charts. flys-artifacts/trunk@1889 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 10 May 2011 17:12:15 +0000
parents 0385bcc4229a
children bab867fb37e8
comparison
equal deleted inserted replaced
418:e0fec407a280 419:4de7d9eac10f
1 package de.intevation.flys.exports; 1 package de.intevation.flys.exports;
2 2
3 import java.awt.BasicStroke;
3 import java.awt.Color; 4 import java.awt.Color;
5 import java.awt.Stroke;
4 6
5 import java.io.IOException; 7 import java.io.IOException;
6 8
7 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
8 10
22 */ 24 */
23 public abstract class XYChartGenerator extends ChartGenerator { 25 public abstract class XYChartGenerator extends ChartGenerator {
24 26
25 /** The logger that is used in this generator.*/ 27 /** The logger that is used in this generator.*/
26 private static Logger logger = Logger.getLogger(ChartGenerator.class); 28 private static Logger logger = Logger.getLogger(ChartGenerator.class);
29
30
31 public static final Color DEFAULT_GRID_COLOR = Color.GRAY;
32 public static final float DEFAULT_GRID_LINE_WIDTH = 0.3f;
27 33
28 34
29 /** 35 /**
30 * Returns the title of a chart. 36 * Returns the title of a chart.
31 * 37 *
72 false); 78 false);
73 79
74 chart.setBackgroundPaint(Color.WHITE); 80 chart.setBackgroundPaint(Color.WHITE);
75 chart.getPlot().setBackgroundPaint(Color.WHITE); 81 chart.getPlot().setBackgroundPaint(Color.WHITE);
76 82
83 XYPlot plot = (XYPlot) chart.getPlot();
84
77 addDatasets(chart); 85 addDatasets(chart);
78 addSubtitles(chart); 86 addSubtitles(chart);
79 adjustAxes((XYPlot) chart.getPlot()); 87 adjustPlot(plot);
88 adjustAxes(plot);
80 89
81 ChartExportHelper.exportImage( 90 ChartExportHelper.exportImage(
82 out, 91 out,
83 chart, 92 chart,
84 "png", 93 "png",
96 105
97 yAxis.setAutoRangeIncludesZero(false); 106 yAxis.setAutoRangeIncludesZero(false);
98 } 107 }
99 108
100 109
110 protected void adjustPlot(XYPlot plot) {
111 Stroke gridStroke = new BasicStroke(
112 DEFAULT_GRID_LINE_WIDTH,
113 BasicStroke.CAP_BUTT,
114 BasicStroke.JOIN_MITER,
115 3.0f,
116 new float[] { 3.0f },
117 0.0f);
118
119 plot.setDomainGridlineStroke(gridStroke);
120 plot.setDomainGridlinePaint(DEFAULT_GRID_COLOR);
121 plot.setDomainGridlinesVisible(true);
122
123 plot.setRangeGridlineStroke(gridStroke);
124 plot.setRangeGridlinePaint(DEFAULT_GRID_COLOR);
125 plot.setRangeGridlinesVisible(true);
126 }
127
128
101 protected void addSubtitles(JFreeChart chart) { 129 protected void addSubtitles(JFreeChart chart) {
102 // override this method in subclasses that need subtitles 130 // override this method in subclasses that need subtitles
103 } 131 }
104 } 132 }
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 133 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org