?? cewolfchartfactory.java
字號:
return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false);
case STACKED_VERTICAL_BAR :
check(data, CategoryDataset.class, chartType);
return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false);
case STACKED_VERTICAL_BAR_3D :
check(data, CategoryDataset.class, chartType);
return ChartFactory.createStackedBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false);
case VERTICAL_BAR :
check(data, CategoryDataset.class, chartType);
return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false);
case VERTICAL_BAR_3D :
check(data, CategoryDataset.class, chartType);
return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false);
case TIME_SERIES :
check(data, XYDataset.class, chartType);
return ChartFactory.createTimeSeriesChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, true, false, false);
case CANDLE_STICK :
check(data, OHLCDataset.class, chartType);
return ChartFactory.createCandlestickChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true);
case HIGH_LOW :
check(data, OHLCDataset.class, chartType);
return ChartFactory.createHighLowChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true);
case GANTT :
check(data, IntervalCategoryDataset.class, chartType);
return ChartFactory.createGanttChart(title, xAxisLabel, yAxisLabel, (IntervalCategoryDataset) data, true, false, false);
case WIND :
check(data, WindDataset.class, chartType);
return ChartFactory.createWindPlot(title, xAxisLabel, yAxisLabel, (WindDataset) data, true, false, false);
//case SIGNAL :
// check(data, SignalsDataset.class, chartType);
// return ChartFactory.createSignalChart(title, xAxisLabel, yAxisLabel, (SignalsDataset) data, true);
case VERRTICAL_XY_BAR :
check(data, IntervalXYDataset.class, chartType);
return ChartFactory.createXYBarChart(title, xAxisLabel, true,yAxisLabel, (IntervalXYDataset) data, PlotOrientation.VERTICAL, true, false, false);
case PIE_3D :
check(data, PieDataset.class, chartType);
return ChartFactory.createPieChart3D(title, (PieDataset) data, true, false, false);
case METER :
check(data, ValueDataset.class, chartType);
MeterPlot plot = new MeterPlot((ValueDataset) data);
JFreeChart chart = new JFreeChart(title, plot);
return chart;
case STACKED_AREA :
check(data, CategoryDataset.class, chartType);
return ChartFactory.createStackedAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false);
case BUBBLE :
check(data, XYZDataset.class, chartType);
return ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, (XYZDataset) data, PlotOrientation.VERTICAL, true, false, false);
default :
throw new UnsupportedChartTypeException(chartType + " is not supported.");
}
}
public static JFreeChart getOverlaidChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel, int xAxisType, int yAxisType, List plotDefinitions)
throws ChartValidationException, DatasetProduceException {
final int chartTypeConst = getChartTypeConstant(chartType);
final AxisFactory axisFactory = AxisFactory.getInstance();
switch (chartTypeConst) {
case OVERLAY_XY :
ValueAxis domainAxis = (ValueAxis) axisFactory.createAxis(ORIENTATION_HORIZONTAL, xAxisType, xAxisLabel);
// get main plot
PlotDefinition mainPlotDef = (PlotDefinition) plotDefinitions.get(0);
check((Dataset) mainPlotDef.getDataset(), XYDataset.class, chartType);
XYPlot plot = (XYPlot) mainPlotDef.getPlot(chartTypeConst);
plot.setDomainAxis(domainAxis);
plot.setRangeAxis((ValueAxis) axisFactory.createAxis(ORIENTATION_VERTICAL, yAxisType, yAxisLabel));
//plot.setRenderer(new StandardXYItemRenderer());
// add second and later datasets to main plot
for (int plotidx = 1;plotidx<plotDefinitions.size();plotidx++) {
PlotDefinition subPlotDef = (PlotDefinition) plotDefinitions.get(plotidx);
check((Dataset) subPlotDef.getDataset(), XYDataset.class, chartType);
plot.setDataset(plotidx, (XYDataset)subPlotDef.getDataset());
int rendererIndex = PlotTypes.getRendererIndex(subPlotDef.getType());
XYItemRenderer rend = (XYItemRenderer) PlotTypes.getRenderer(rendererIndex);
plot.setRenderer(plotidx, rend);
}
return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
case OVERLAY_CATEGORY ://added by lrh 2005-07-11
CategoryAxis domainAxis2 = (CategoryAxis)axisFactory.createAxis(ORIENTATION_HORIZONTAL, xAxisType, xAxisLabel);
// get main plot
mainPlotDef = (PlotDefinition) plotDefinitions.get(0);
check((Dataset) mainPlotDef.getDataset(), CategoryDataset.class, chartType);
CategoryPlot plot2 = (CategoryPlot) mainPlotDef.getPlot(chartTypeConst);
plot2.setDomainAxis(domainAxis2);
plot2.setRangeAxis((ValueAxis)axisFactory.createAxis(ORIENTATION_VERTICAL, yAxisType, yAxisLabel));
//plot.setRenderer(new StandardXYItemRenderer());
// add second and later datasets to main plot
for (int plotidx = 1;plotidx<plotDefinitions.size();plotidx++) {
PlotDefinition subPlotDef = (PlotDefinition) plotDefinitions.get(plotidx);
check((Dataset) subPlotDef.getDataset(), CategoryDataset.class, chartType);
plot2.setDataset(plotidx, (CategoryDataset)subPlotDef.getDataset());
int rendererIndex = PlotTypes.getRendererIndex(subPlotDef.getType());
CategoryItemRenderer rend2 = (CategoryItemRenderer) PlotTypes.getRenderer(rendererIndex);
plot2.setRenderer(plotidx, rend2);
}
return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot2, true);
default :
throw new UnsupportedChartTypeException(chartType + " is not supported.");
}
}
// [tb]
public static JFreeChart getCombinedChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel, List plotDefinitions, String layout)
throws ChartValidationException, DatasetProduceException {
final int chartTypeConst = getChartTypeConstant(chartType);
switch (chartTypeConst) {
case COMBINED_XY :
final int layoutConst = getLayoutConstant(layout);
Plot plot = null;
switch (layoutConst) {
case DOMAIN :
ValueAxis domainAxis = new DateAxis(xAxisLabel);
plot = new CombinedDomainXYPlot(domainAxis);
for (int i = 0; i < plotDefinitions.size(); i++) {
PlotDefinition pd = (PlotDefinition) plotDefinitions.get(i);
check((Dataset) pd.getDataset(), XYDataset.class, chartType);
XYPlot temp = (XYPlot) pd.getPlot(chartTypeConst);
temp.setRangeAxis(new NumberAxis(pd.getYaxislabel()));
((CombinedDomainXYPlot) plot).add(temp);
}
return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
case RANGE :
ValueAxis rangeAxis = new NumberAxis(yAxisLabel);
plot = new CombinedRangeXYPlot(rangeAxis);
for (int i = 0; i < plotDefinitions.size(); i++) {
PlotDefinition pd = (PlotDefinition) plotDefinitions.get(i);
check((Dataset) pd.getDataset(), XYDataset.class, chartType);
XYPlot temp = (XYPlot) pd.getPlot(chartTypeConst);
temp.setDomainAxis(new DateAxis(pd.getXaxislabel()));
((CombinedRangeXYPlot) plot).add(temp);
}
return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
default :
throw new AttributeValidationException(layout, " any value");
}
default :
throw new UnsupportedChartTypeException(chartType);
}
}
/**
* Helper to check if the given dataset is the expected type.
* @param data The dataset
* @param clazz Expected type (class)
* @param chartType The chart type string
* @throws IncompatibleDatasetException If not the expected class
*/
public static void check(Dataset data, Class clazz, String chartType) throws IncompatibleDatasetException {
if (!clazz.isInstance(data)) {
throw new IncompatibleDatasetException("Charts of type " + chartType + " " + "need datasets of type " + clazz.getName());
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -