Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractHistogram.java @ 875:5e9efdda6894
merged gnv-artifacts/1.0
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:56 +0200 |
parents | 79401c871da4 |
children | 86ca3c10523f |
comparison
equal
deleted
inserted
replaced
722:bb3ffe7d719e | 875:5e9efdda6894 |
---|---|
1 package de.intevation.gnv.chart; | |
2 | |
3 import java.util.Locale; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.jfree.chart.ChartFactory; | |
8 import org.jfree.chart.ChartTheme; | |
9 import org.jfree.chart.JFreeChart; | |
10 | |
11 import org.jfree.chart.plot.PlotOrientation; | |
12 import org.jfree.chart.plot.XYPlot; | |
13 | |
14 import org.jfree.chart.renderer.xy.XYBarRenderer; | |
15 | |
16 /** | |
17 * This abstract class defines some methods to adjust chart settings after its | |
18 * creation. | |
19 * | |
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
21 */ | |
22 public abstract class AbstractHistogram | |
23 implements Chart | |
24 { | |
25 /** | |
26 * Logger used for logging with Apache log4j. | |
27 */ | |
28 private Logger logger = Logger.getLogger(AbstractHistogram.class); | |
29 | |
30 /** | |
31 * JFreeChart chart stored at this place after chart creation. | |
32 */ | |
33 protected JFreeChart chart; | |
34 | |
35 /** | |
36 * Labels used for chart title, subtitle, axis description. | |
37 */ | |
38 protected ChartLabels labels; | |
39 | |
40 /** | |
41 * Theme which is used to adjust the styling of this chart. | |
42 */ | |
43 protected ChartTheme theme; | |
44 | |
45 /** | |
46 * Raw data which should be displayed in the chart. | |
47 */ | |
48 protected Object[] data; | |
49 | |
50 /** | |
51 * Locale object used for i18n support. | |
52 */ | |
53 protected Locale locale; | |
54 | |
55 | |
56 /** | |
57 * Constructor for creating histogram charts. | |
58 * | |
59 * @param labels See {@link #labels} | |
60 * @param data See {@link #data} | |
61 * @param theme See {@link #theme} | |
62 */ | |
63 public AbstractHistogram( | |
64 ChartLabels labels, Object[] data, ChartTheme theme | |
65 ) { | |
66 this.labels = labels; | |
67 this.data = data; | |
68 this.theme = theme; | |
69 } | |
70 | |
71 | |
72 /** | |
73 * @see de.intevation.gnv.chart.Chart#generateChart() | |
74 */ | |
75 public JFreeChart generateChart() { | |
76 | |
77 if (chart != null) | |
78 return chart; | |
79 | |
80 chart = ChartFactory.createHistogram( | |
81 labels.getTitle(), | |
82 labels.getDomainAxisLabel(), | |
83 labels.getRangeAxisLabel(), | |
84 null, | |
85 PlotOrientation.VERTICAL, | |
86 true, | |
87 false, | |
88 false); | |
89 | |
90 applyDatasets(); | |
91 | |
92 theme.apply(chart); | |
93 adjustPlot(); | |
94 | |
95 return chart; | |
96 } | |
97 | |
98 | |
99 /** | |
100 * Method to do some changes in plot settings. | |
101 */ | |
102 protected void adjustPlot() { | |
103 XYPlot plot = (XYPlot) chart.getPlot(); | |
104 XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); | |
105 | |
106 renderer.setShadowVisible(false); | |
107 renderer.setSeriesVisibleInLegend(0, false); | |
108 } | |
109 | |
110 | |
111 /** | |
112 * This method needs to be implemented by subclasses and should add valid | |
113 * <code>HistogramDataset</code> objects to the created chart. It is called | |
114 * by {@link #generateChart} after chart creation. | |
115 */ | |
116 protected abstract void applyDatasets(); | |
117 } | |
118 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |