List of usage examples for org.jfree.data.category DefaultCategoryDataset setGroup
@Override public void setGroup(DatasetGroup group)
From source file:org.toobsframework.pres.chart.ChartBuilder.java
private Plot configurePlot(IRequest componentRequest, String id, BasePlot plotDef, Map params, boolean isSubPlot, int parentPlotType, BasePlot parentPlot) throws ChartException { boolean is3D = (ParameterUtil.resolveParam(componentRequest, plotDef.getIs3D(), params, "false")[0] .equals("false") ? false : true); Integer plotType = ChartUtil.getSupportedPlots() .get(ParameterUtil.resolveParam(componentRequest, plotDef.getType(), params, "multiCategory")[0]); if (plotType == null) { throw new ChartException("Unsupported Plot type " + ParameterUtil.resolveParam(componentRequest, plotDef.getType(), params, "multiCategory")[0]); }//from ww w .j a va 2s. c o m Plot plot = null; switch (plotType) { case ChartUtil.PLOT_CATEGORY_TYPE: DomainAxisDef domainAxis = null; RangeAxisDef rangeAxis = null; plot = new CategoryPlot(); if (isSubPlot) { if (plotDef.getDomainAxisDef() != null && parentPlotType != ChartUtil.PLOT_COMBINEDDOMAINCATEGORY_TYPE) { domainAxis = plotDef.getDomainAxisDef(); } else if (parentPlotType != ChartUtil.PLOT_COMBINEDDOMAINCATEGORY_TYPE) { domainAxis = parentPlot.getDomainAxisDef(); } if (plotDef.getRangeAxisDef() != null && parentPlotType != ChartUtil.PLOT_COMBINEDRANGECATEGORY_TYPE) { rangeAxis = plotDef.getRangeAxisDef(); } else if (parentPlotType != ChartUtil.PLOT_COMBINEDRANGECATEGORY_TYPE) { rangeAxis = parentPlot.getRangeAxisDef(); } } else { domainAxis = plotDef.getDomainAxisDef(); rangeAxis = plotDef.getRangeAxisDef(); } ((CategoryPlot) plot) .setDomainAxis(ChartUtil.createCategoryAxis(componentRequest, domainAxis, params, is3D)); ((CategoryPlot) plot).setRangeAxis(createValueAxis(componentRequest, rangeAxis, params, is3D)); for (int g = 0; g < plotDef.getDatasetGroupCount(); g++) { org.toobsframework.pres.chart.config.DatasetGroup group = plotDef.getDatasetGroup(g); CategoryItemRenderer renderer = (CategoryItemRenderer) ChartUtil.getRenderer(componentRequest, plotDef, group, params); if (group.getUrlBase() != null) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator(group.getUrlBase())); } ((CategoryPlot) plot).setRenderer(g, renderer); DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset(); if (group.getId() != null) { DatasetGroup datasetGroup = new DatasetGroup(group.getId()); categoryDataset.setGroup(datasetGroup); } for (int i = 0; i < group.getDatasetCount(); i++) { Dataset dataset = group.getDataset(i); generateCategoryDataset(componentRequest, id, categoryDataset, dataset, params); this.setValueAxisBounds(componentRequest, ((CategoryPlot) plot).getRangeAxis(), rangeAxis, params); } ((CategoryPlot) plot).setDataset(g, categoryDataset); } ChartUtil.configurePlot(componentRequest, plot, plotDef, domainAxis, rangeAxis, params); break; case ChartUtil.PLOT_XY_TYPE: plot = new XYPlot(); break; case ChartUtil.PLOT_SPIDER_TYPE: plot = new SpiderWebPlot(); DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset(); for (int g = 0; g < plotDef.getDatasetGroupCount(); g++) { org.toobsframework.pres.chart.config.DatasetGroup group = plotDef.getDatasetGroup(g); if (group.getUrlBase() != null) { ((SpiderWebPlot) plot).setURLGenerator(new StandardCategoryURLGenerator(group.getUrlBase())); } if (group.getId() != null) { DatasetGroup datasetGroup = new DatasetGroup(group.getId()); categoryDataset.setGroup(datasetGroup); } for (int i = 0; i < group.getDatasetCount(); i++) { Dataset dataset = group.getDataset(i); //generateCategoryDataset(id, categoryDataset, dataset, params); for (int s = 0; s < dataset.getDatasetSeriesCount(); s++) { DatasetSeries series = dataset.getDatasetSeries(s); if (series.getColor() != null) { ((SpiderWebPlot) plot).setSeriesPaint(i + s, ChartUtil.getColor(series.getColor())); } } } } ((SpiderWebPlot) plot).setDataset(categoryDataset); ChartUtil.configurePlot(componentRequest, plot, plotDef, null, null, params); break; } return plot; }