franta-hg@1
|
1 |
/* ================================================================
|
franta-hg@1
|
2 |
* Cewolf : Chart enabling Web Objects Framework
|
franta-hg@1
|
3 |
* ================================================================
|
franta-hg@1
|
4 |
*
|
franta-hg@1
|
5 |
* Project Info: http://cewolf.sourceforge.net
|
franta-hg@1
|
6 |
* Project Lead: Guido Laures (guido@laures.de);
|
franta-hg@1
|
7 |
*
|
franta-hg@1
|
8 |
* (C) Copyright 2002, by Guido Laures
|
franta-hg@1
|
9 |
*
|
franta-hg@1
|
10 |
* This library is free software; you can redistribute it and/or modify it under the terms
|
franta-hg@1
|
11 |
* of the GNU Lesser General Public License as published by the Free Software Foundation;
|
franta-hg@1
|
12 |
* either version 2.1 of the License, or (at your option) any later version.
|
franta-hg@1
|
13 |
*
|
franta-hg@1
|
14 |
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
franta-hg@1
|
15 |
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
franta-hg@1
|
16 |
* See the GNU Lesser General Public License for more details.
|
franta-hg@1
|
17 |
*
|
franta-hg@1
|
18 |
* You should have received a copy of the GNU Lesser General Public License along with this
|
franta-hg@1
|
19 |
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
franta-hg@1
|
20 |
* Boston, MA 02111-1307, USA.
|
franta-hg@1
|
21 |
*/
|
franta-hg@1
|
22 |
|
franta-hg@1
|
23 |
package de.laures.cewolf.taglib;
|
franta-hg@1
|
24 |
|
franta-hg@1
|
25 |
import java.util.HashMap;
|
franta-hg@1
|
26 |
import java.util.List;
|
franta-hg@1
|
27 |
import java.util.Map;
|
franta-hg@1
|
28 |
|
franta-hg@1
|
29 |
import org.jfree.chart.ChartFactory;
|
franta-hg@1
|
30 |
import org.jfree.chart.JFreeChart;
|
franta-hg@1
|
31 |
import org.jfree.chart.axis.CategoryAxis;
|
franta-hg@1
|
32 |
import org.jfree.chart.axis.DateAxis;
|
franta-hg@1
|
33 |
import org.jfree.chart.axis.NumberAxis;
|
franta-hg@1
|
34 |
import org.jfree.chart.axis.ValueAxis;
|
franta-hg@1
|
35 |
import org.jfree.chart.plot.CategoryPlot;
|
franta-hg@1
|
36 |
import org.jfree.chart.plot.CombinedDomainXYPlot;
|
franta-hg@1
|
37 |
import org.jfree.chart.plot.CombinedRangeXYPlot;
|
franta-hg@1
|
38 |
import org.jfree.chart.plot.MeterPlot;
|
franta-hg@1
|
39 |
import org.jfree.chart.plot.Plot;
|
franta-hg@1
|
40 |
import org.jfree.chart.plot.PlotOrientation;
|
franta-hg@1
|
41 |
import org.jfree.chart.plot.XYPlot;
|
franta-hg@1
|
42 |
import org.jfree.chart.renderer.category.CategoryItemRenderer;
|
franta-hg@1
|
43 |
import org.jfree.chart.renderer.xy.XYItemRenderer;
|
franta-hg@1
|
44 |
import org.jfree.data.category.CategoryDataset;
|
franta-hg@1
|
45 |
import org.jfree.data.category.IntervalCategoryDataset;
|
franta-hg@1
|
46 |
import org.jfree.data.general.Dataset;
|
franta-hg@1
|
47 |
import org.jfree.data.general.PieDataset;
|
franta-hg@1
|
48 |
import org.jfree.data.general.ValueDataset;
|
franta-hg@1
|
49 |
import org.jfree.data.xy.IntervalXYDataset;
|
franta-hg@1
|
50 |
import org.jfree.data.xy.OHLCDataset;
|
franta-hg@1
|
51 |
import org.jfree.data.xy.WindDataset;
|
franta-hg@1
|
52 |
import org.jfree.data.xy.XYDataset;
|
franta-hg@1
|
53 |
import org.jfree.data.xy.XYZDataset;
|
franta-hg@1
|
54 |
|
franta-hg@1
|
55 |
import de.laures.cewolf.ChartValidationException;
|
franta-hg@1
|
56 |
import de.laures.cewolf.DatasetProduceException;
|
franta-hg@1
|
57 |
|
franta-hg@1
|
58 |
/**
|
franta-hg@1
|
59 |
* Chart factory creates Jfreechart instances. To add a new factory use the
|
franta-hg@1
|
60 |
* <code>
|
franta-hg@1
|
61 |
* CewolfChartFactory.registerFactory(new CewolfChartFactory() {...});
|
franta-hg@1
|
62 |
* </code>
|
franta-hg@1
|
63 |
* method.
|
franta-hg@1
|
64 |
*
|
franta-hg@1
|
65 |
* @author Guido Laures
|
franta-hg@1
|
66 |
*/
|
franta-hg@1
|
67 |
public abstract class CewolfChartFactory implements ChartConstants, AxisConstants, LayoutConstants {
|
franta-hg@1
|
68 |
|
franta-hg@1
|
69 |
// chart type string
|
franta-hg@1
|
70 |
protected String chartType;
|
franta-hg@1
|
71 |
// map contains registered factories, (String) chartType->CewolfChartFactory mappings
|
franta-hg@1
|
72 |
private static Map factories = new HashMap();
|
franta-hg@1
|
73 |
|
franta-hg@1
|
74 |
/** Creates a new instance of ChartFactory */
|
franta-hg@1
|
75 |
protected CewolfChartFactory(String chartType) {
|
franta-hg@1
|
76 |
this.chartType = chartType;
|
franta-hg@1
|
77 |
}
|
franta-hg@1
|
78 |
|
franta-hg@1
|
79 |
/**
|
franta-hg@1
|
80 |
* Callback when the chart instance to be created.
|
franta-hg@1
|
81 |
* @param title The title of chart
|
franta-hg@1
|
82 |
* @param xAxisLabel label on x axis
|
franta-hg@1
|
83 |
* @param yAxisLabel label on y axis
|
franta-hg@1
|
84 |
* @param data The dataset to create chart for
|
franta-hg@1
|
85 |
* @return The newly created JFreeChart instance
|
franta-hg@1
|
86 |
*
|
franta-hg@1
|
87 |
* @throws IncompatibleDatasetException If the incoming data is not compatible with this factory
|
franta-hg@1
|
88 |
*/
|
franta-hg@1
|
89 |
public abstract JFreeChart getChartInstance(String title, String xAxisLabel, String yAxisLabel, Dataset data) throws IncompatibleDatasetException;
|
franta-hg@1
|
90 |
|
franta-hg@1
|
91 |
//////////////// static part ///////////////////////
|
franta-hg@1
|
92 |
|
franta-hg@1
|
93 |
/**
|
franta-hg@1
|
94 |
* Register a new chart factory instance.
|
franta-hg@1
|
95 |
* @param factory The factory to register
|
franta-hg@1
|
96 |
*/
|
franta-hg@1
|
97 |
public static void registerFactory(CewolfChartFactory factory) {
|
franta-hg@1
|
98 |
factories.put(factory.chartType, factory);
|
franta-hg@1
|
99 |
}
|
franta-hg@1
|
100 |
|
franta-hg@1
|
101 |
private static final int getChartTypeConstant(String type) {
|
franta-hg@1
|
102 |
final int res = ChartTypes.typeList.indexOf(type.toLowerCase());
|
franta-hg@1
|
103 |
if (res < 0) {
|
franta-hg@1
|
104 |
throw new RuntimeException("unsupported chart type " + type);
|
franta-hg@1
|
105 |
}
|
franta-hg@1
|
106 |
return res;
|
franta-hg@1
|
107 |
}
|
franta-hg@1
|
108 |
|
franta-hg@1
|
109 |
private static final int getLayoutConstant(String layout) {
|
franta-hg@1
|
110 |
return LayoutTypes.typeList.indexOf(layout.toLowerCase());
|
franta-hg@1
|
111 |
}
|
franta-hg@1
|
112 |
|
franta-hg@1
|
113 |
static {
|
franta-hg@1
|
114 |
// histogram chart type
|
franta-hg@1
|
115 |
registerFactory(new CewolfChartFactory("histogram") {
|
franta-hg@1
|
116 |
public JFreeChart getChartInstance(String title, String xAxisLabel, String yAxisLabel, Dataset data) throws IncompatibleDatasetException {
|
franta-hg@1
|
117 |
check(data, IntervalXYDataset.class, this.chartType);
|
franta-hg@1
|
118 |
return ChartFactory.createHistogram(title, xAxisLabel, yAxisLabel, (IntervalXYDataset) data, PlotOrientation.VERTICAL, true, false, false);
|
franta-hg@1
|
119 |
}
|
franta-hg@1
|
120 |
});
|
franta-hg@1
|
121 |
}
|
franta-hg@1
|
122 |
|
franta-hg@1
|
123 |
public static JFreeChart getChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel, Dataset data) throws ChartValidationException {
|
franta-hg@1
|
124 |
// first check the dynamically registered chart types
|
franta-hg@1
|
125 |
CewolfChartFactory factory = (CewolfChartFactory) factories.get(chartType);
|
franta-hg@1
|
126 |
if (factory != null) {
|
franta-hg@1
|
127 |
// custom factory found, use it
|
franta-hg@1
|
128 |
return factory.getChartInstance(title, xAxisLabel, yAxisLabel, data);
|
franta-hg@1
|
129 |
}
|
franta-hg@1
|
130 |
|
franta-hg@1
|
131 |
switch (getChartTypeConstant(chartType)) {
|
franta-hg@1
|
132 |
case XY :
|
franta-hg@1
|
133 |
check(data, XYDataset.class, chartType);
|
franta-hg@1
|
134 |
return ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, PlotOrientation.VERTICAL, true, true, true);
|
franta-hg@1
|
135 |
case PIE :
|
franta-hg@1
|
136 |
check(data, PieDataset.class, chartType);
|
franta-hg@1
|
137 |
return ChartFactory.createPieChart(title, (PieDataset) data, true, true, true);
|
franta-hg@1
|
138 |
case AREA_XY :
|
franta-hg@1
|
139 |
check(data, XYDataset.class, chartType);
|
franta-hg@1
|
140 |
return ChartFactory.createXYAreaChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, PlotOrientation.VERTICAL, true, false, false);
|
franta-hg@1
|
141 |
case SCATTER :
|
franta-hg@1
|
142 |
check(data, XYDataset.class, chartType);
|
franta-hg@1
|
143 |
return ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, (XYDataset) data, PlotOrientation.VERTICAL, true, false, false);
|
franta-hg@1
|
144 |
case AREA :
|
franta-hg@1
|
145 |
check(data, CategoryDataset.class, chartType);
|
franta-hg@1
|
146 |
return ChartFactory.createAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false);
|
franta-hg@1
|
147 |
case HORIZONTAL_BAR :
|
franta-hg@1
|
148 |
check(data, CategoryDataset.class, chartType);
|
franta-hg@1
|
149 |
return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false);
|
franta-hg@1
|
150 |
case HORIZONTAL_BAR_3D :
|
franta-hg@1
|
151 |
check(data, CategoryDataset.class, chartType);
|
franta-hg@1
|
152 |
return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false);
|
franta-hg@1
|
153 |
case LINE :
|
franta-hg@1
|
154 |
check(data, CategoryDataset.class, chartType);
|
franta-hg@1
|
155 |
return ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false);
|
franta-hg@1
|
156 |
case STACKED_HORIZONTAL_BAR :
|
franta-hg@1
|
157 |
check(data, CategoryDataset.class, chartType);
|
franta-hg@1
|
158 |
return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false);
|
franta-hg@1
|
159 |
case STACKED_VERTICAL_BAR :
|
franta-hg@1
|
160 |
check(data, CategoryDataset.class, chartType);
|
franta-hg@1
|
161 |
return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false);
|
franta-hg@1
|
162 |
case STACKED_VERTICAL_BAR_3D :
|
franta-hg@1
|
163 |
check(data, CategoryDataset.class, chartType);
|
franta-hg@1
|
164 |
return ChartFactory.createStackedBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false);
|
franta-hg@1
|
165 |
case VERTICAL_BAR :
|
franta-hg@1
|
166 |
check(data, CategoryDataset.class, chartType);
|
franta-hg@1
|
167 |
return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false);
|
franta-hg@1
|
168 |
case VERTICAL_BAR_3D :
|
franta-hg@1
|
169 |
check(data, CategoryDataset.class, chartType);
|
franta-hg@1
|
170 |
return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false);
|
franta-hg@1
|
171 |
case TIME_SERIES :
|
franta-hg@1
|
172 |
check(data, XYDataset.class, chartType);
|
franta-hg@1
|
173 |
return ChartFactory.createTimeSeriesChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, true, false, false);
|
franta-hg@1
|
174 |
case CANDLE_STICK :
|
franta-hg@1
|
175 |
check(data, OHLCDataset.class, chartType);
|
franta-hg@1
|
176 |
return ChartFactory.createCandlestickChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true);
|
franta-hg@1
|
177 |
case HIGH_LOW :
|
franta-hg@1
|
178 |
check(data, OHLCDataset.class, chartType);
|
franta-hg@1
|
179 |
return ChartFactory.createHighLowChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true);
|
franta-hg@1
|
180 |
case GANTT :
|
franta-hg@1
|
181 |
check(data, IntervalCategoryDataset.class, chartType);
|
franta-hg@1
|
182 |
return ChartFactory.createGanttChart(title, xAxisLabel, yAxisLabel, (IntervalCategoryDataset) data, true, false, false);
|
franta-hg@1
|
183 |
case WIND :
|
franta-hg@1
|
184 |
check(data, WindDataset.class, chartType);
|
franta-hg@1
|
185 |
return ChartFactory.createWindPlot(title, xAxisLabel, yAxisLabel, (WindDataset) data, true, false, false);
|
franta-hg@1
|
186 |
//case SIGNAL :
|
franta-hg@1
|
187 |
// check(data, SignalsDataset.class, chartType);
|
franta-hg@1
|
188 |
// return ChartFactory.createSignalChart(title, xAxisLabel, yAxisLabel, (SignalsDataset) data, true);
|
franta-hg@1
|
189 |
case VERRTICAL_XY_BAR :
|
franta-hg@1
|
190 |
check(data, IntervalXYDataset.class, chartType);
|
franta-hg@1
|
191 |
return ChartFactory.createXYBarChart(title, xAxisLabel, true,yAxisLabel, (IntervalXYDataset) data, PlotOrientation.VERTICAL, true, false, false);
|
franta-hg@1
|
192 |
case PIE_3D :
|
franta-hg@1
|
193 |
check(data, PieDataset.class, chartType);
|
franta-hg@1
|
194 |
return ChartFactory.createPieChart3D(title, (PieDataset) data, true, false, false);
|
franta-hg@1
|
195 |
case METER :
|
franta-hg@1
|
196 |
check(data, ValueDataset.class, chartType);
|
franta-hg@1
|
197 |
MeterPlot plot = new MeterPlot((ValueDataset) data);
|
franta-hg@1
|
198 |
JFreeChart chart = new JFreeChart(title, plot);
|
franta-hg@1
|
199 |
return chart;
|
franta-hg@1
|
200 |
case STACKED_AREA :
|
franta-hg@1
|
201 |
check(data, CategoryDataset.class, chartType);
|
franta-hg@1
|
202 |
return ChartFactory.createStackedAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false);
|
franta-hg@1
|
203 |
case BUBBLE :
|
franta-hg@1
|
204 |
check(data, XYZDataset.class, chartType);
|
franta-hg@1
|
205 |
return ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, (XYZDataset) data, PlotOrientation.VERTICAL, true, false, false);
|
franta-hg@1
|
206 |
default :
|
franta-hg@1
|
207 |
throw new UnsupportedChartTypeException(chartType + " is not supported.");
|
franta-hg@1
|
208 |
}
|
franta-hg@1
|
209 |
}
|
franta-hg@1
|
210 |
|
franta-hg@1
|
211 |
public static JFreeChart getOverlaidChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel, int xAxisType, int yAxisType, List plotDefinitions)
|
franta-hg@1
|
212 |
throws ChartValidationException, DatasetProduceException {
|
franta-hg@1
|
213 |
final int chartTypeConst = getChartTypeConstant(chartType);
|
franta-hg@1
|
214 |
final AxisFactory axisFactory = AxisFactory.getInstance();
|
franta-hg@1
|
215 |
switch (chartTypeConst) {
|
franta-hg@1
|
216 |
case OVERLAY_XY :
|
franta-hg@1
|
217 |
ValueAxis domainAxis = (ValueAxis) axisFactory.createAxis(ORIENTATION_HORIZONTAL, xAxisType, xAxisLabel);
|
franta-hg@1
|
218 |
// get main plot
|
franta-hg@1
|
219 |
PlotDefinition mainPlotDef = (PlotDefinition) plotDefinitions.get(0);
|
franta-hg@1
|
220 |
check((Dataset) mainPlotDef.getDataset(), XYDataset.class, chartType);
|
franta-hg@1
|
221 |
XYPlot plot = (XYPlot) mainPlotDef.getPlot(chartTypeConst);
|
franta-hg@1
|
222 |
plot.setDomainAxis(domainAxis);
|
franta-hg@1
|
223 |
plot.setRangeAxis((ValueAxis) axisFactory.createAxis(ORIENTATION_VERTICAL, yAxisType, yAxisLabel));
|
franta-hg@1
|
224 |
//plot.setRenderer(new StandardXYItemRenderer());
|
franta-hg@1
|
225 |
// add second and later datasets to main plot
|
franta-hg@1
|
226 |
for (int plotidx = 1;plotidx<plotDefinitions.size();plotidx++) {
|
franta-hg@1
|
227 |
PlotDefinition subPlotDef = (PlotDefinition) plotDefinitions.get(plotidx);
|
franta-hg@1
|
228 |
check((Dataset) subPlotDef.getDataset(), XYDataset.class, chartType);
|
franta-hg@1
|
229 |
plot.setDataset(plotidx, (XYDataset)subPlotDef.getDataset());
|
franta-hg@1
|
230 |
|
franta-hg@1
|
231 |
int rendererIndex = PlotTypes.getRendererIndex(subPlotDef.getType());
|
franta-hg@1
|
232 |
XYItemRenderer rend = (XYItemRenderer) PlotTypes.getRenderer(rendererIndex);
|
franta-hg@1
|
233 |
plot.setRenderer(plotidx, rend);
|
franta-hg@1
|
234 |
}
|
franta-hg@1
|
235 |
return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
|
franta-hg@1
|
236 |
case OVERLAY_CATEGORY ://added by lrh 2005-07-11
|
franta-hg@1
|
237 |
CategoryAxis domainAxis2 = (CategoryAxis)axisFactory.createAxis(ORIENTATION_HORIZONTAL, xAxisType, xAxisLabel);
|
franta-hg@1
|
238 |
// get main plot
|
franta-hg@1
|
239 |
mainPlotDef = (PlotDefinition) plotDefinitions.get(0);
|
franta-hg@1
|
240 |
check((Dataset) mainPlotDef.getDataset(), CategoryDataset.class, chartType);
|
franta-hg@1
|
241 |
CategoryPlot plot2 = (CategoryPlot) mainPlotDef.getPlot(chartTypeConst);
|
franta-hg@1
|
242 |
plot2.setDomainAxis(domainAxis2);
|
franta-hg@1
|
243 |
plot2.setRangeAxis((ValueAxis)axisFactory.createAxis(ORIENTATION_VERTICAL, yAxisType, yAxisLabel));
|
franta-hg@1
|
244 |
//plot.setRenderer(new StandardXYItemRenderer());
|
franta-hg@1
|
245 |
// add second and later datasets to main plot
|
franta-hg@1
|
246 |
for (int plotidx = 1;plotidx<plotDefinitions.size();plotidx++) {
|
franta-hg@1
|
247 |
PlotDefinition subPlotDef = (PlotDefinition) plotDefinitions.get(plotidx);
|
franta-hg@1
|
248 |
check((Dataset) subPlotDef.getDataset(), CategoryDataset.class, chartType);
|
franta-hg@1
|
249 |
plot2.setDataset(plotidx, (CategoryDataset)subPlotDef.getDataset());
|
franta-hg@1
|
250 |
|
franta-hg@1
|
251 |
int rendererIndex = PlotTypes.getRendererIndex(subPlotDef.getType());
|
franta-hg@1
|
252 |
CategoryItemRenderer rend2 = (CategoryItemRenderer) PlotTypes.getRenderer(rendererIndex);
|
franta-hg@1
|
253 |
plot2.setRenderer(plotidx, rend2);
|
franta-hg@1
|
254 |
}
|
franta-hg@1
|
255 |
return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot2, true);
|
franta-hg@1
|
256 |
default :
|
franta-hg@1
|
257 |
throw new UnsupportedChartTypeException(chartType + " is not supported.");
|
franta-hg@1
|
258 |
}
|
franta-hg@1
|
259 |
}
|
franta-hg@1
|
260 |
|
franta-hg@1
|
261 |
// [tb]
|
franta-hg@1
|
262 |
public static JFreeChart getCombinedChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel, List plotDefinitions, String layout)
|
franta-hg@1
|
263 |
throws ChartValidationException, DatasetProduceException {
|
franta-hg@1
|
264 |
final int chartTypeConst = getChartTypeConstant(chartType);
|
franta-hg@1
|
265 |
switch (chartTypeConst) {
|
franta-hg@1
|
266 |
case COMBINED_XY :
|
franta-hg@1
|
267 |
final int layoutConst = getLayoutConstant(layout);
|
franta-hg@1
|
268 |
Plot plot = null;
|
franta-hg@1
|
269 |
switch (layoutConst) {
|
franta-hg@1
|
270 |
case DOMAIN :
|
franta-hg@1
|
271 |
ValueAxis domainAxis = new DateAxis(xAxisLabel);
|
franta-hg@1
|
272 |
plot = new CombinedDomainXYPlot(domainAxis);
|
franta-hg@1
|
273 |
for (int i = 0; i < plotDefinitions.size(); i++) {
|
franta-hg@1
|
274 |
PlotDefinition pd = (PlotDefinition) plotDefinitions.get(i);
|
franta-hg@1
|
275 |
check((Dataset) pd.getDataset(), XYDataset.class, chartType);
|
franta-hg@1
|
276 |
XYPlot temp = (XYPlot) pd.getPlot(chartTypeConst);
|
franta-hg@1
|
277 |
temp.setRangeAxis(new NumberAxis(pd.getYaxislabel()));
|
franta-hg@1
|
278 |
((CombinedDomainXYPlot) plot).add(temp);
|
franta-hg@1
|
279 |
}
|
franta-hg@1
|
280 |
return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
|
franta-hg@1
|
281 |
case RANGE :
|
franta-hg@1
|
282 |
ValueAxis rangeAxis = new NumberAxis(yAxisLabel);
|
franta-hg@1
|
283 |
plot = new CombinedRangeXYPlot(rangeAxis);
|
franta-hg@1
|
284 |
for (int i = 0; i < plotDefinitions.size(); i++) {
|
franta-hg@1
|
285 |
PlotDefinition pd = (PlotDefinition) plotDefinitions.get(i);
|
franta-hg@1
|
286 |
check((Dataset) pd.getDataset(), XYDataset.class, chartType);
|
franta-hg@1
|
287 |
XYPlot temp = (XYPlot) pd.getPlot(chartTypeConst);
|
franta-hg@1
|
288 |
temp.setDomainAxis(new DateAxis(pd.getXaxislabel()));
|
franta-hg@1
|
289 |
((CombinedRangeXYPlot) plot).add(temp);
|
franta-hg@1
|
290 |
}
|
franta-hg@1
|
291 |
return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
|
franta-hg@1
|
292 |
default :
|
franta-hg@1
|
293 |
throw new AttributeValidationException(layout, " any value");
|
franta-hg@1
|
294 |
}
|
franta-hg@1
|
295 |
default :
|
franta-hg@1
|
296 |
throw new UnsupportedChartTypeException(chartType);
|
franta-hg@1
|
297 |
}
|
franta-hg@1
|
298 |
}
|
franta-hg@1
|
299 |
|
franta-hg@1
|
300 |
/**
|
franta-hg@1
|
301 |
* Helper to check if the given dataset is the expected type.
|
franta-hg@1
|
302 |
* @param data The dataset
|
franta-hg@1
|
303 |
* @param clazz Expected type (class)
|
franta-hg@1
|
304 |
* @param chartType The chart type string
|
franta-hg@1
|
305 |
* @throws IncompatibleDatasetException If not the expected class
|
franta-hg@1
|
306 |
*/
|
franta-hg@1
|
307 |
public static void check(Dataset data, Class clazz, String chartType) throws IncompatibleDatasetException {
|
franta-hg@1
|
308 |
if (!clazz.isInstance(data)) {
|
franta-hg@1
|
309 |
throw new IncompatibleDatasetException("Charts of type " + chartType + " " + "need datasets of type " + clazz.getName());
|
franta-hg@1
|
310 |
}
|
franta-hg@1
|
311 |
}
|
franta-hg@1
|
312 |
|
franta-hg@1
|
313 |
}
|