use of com.xpn.xwiki.plugin.charts.exceptions.GenerateException in project xwiki-platform by xwiki.
the class BarPlotFactory method create.
@Override
public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException {
Class rendererClass = params.getClass(ChartParams.RENDERER);
if (rendererClass == null || CategoryItemRenderer.class.isAssignableFrom(rendererClass)) {
CategoryItemRenderer renderer;
if (rendererClass != null) {
try {
Constructor ctor = rendererClass.getConstructor(new Class[] {});
renderer = (CategoryItemRenderer) ctor.newInstance(new Object[] {});
} catch (Throwable e) {
throw new GenerateException(e);
}
} else {
renderer = new BarRenderer();
}
return CategoryPlotFactory.getInstance().create(dataSource, renderer, params);
} else if (XYItemRenderer.class.isAssignableFrom(rendererClass)) {
XYItemRenderer renderer;
try {
Constructor ctor = rendererClass.getConstructor(new Class[] {});
renderer = (XYItemRenderer) ctor.newInstance(new Object[] {});
} catch (Throwable e) {
throw new GenerateException(e);
}
ChartCustomizer.customizeXYItemRenderer(renderer, params);
return XYPlotFactory.getInstance().create(dataSource, renderer, params);
} else {
throw new GenerateException("Incompatible renderer class: " + rendererClass);
}
}
use of com.xpn.xwiki.plugin.charts.exceptions.GenerateException in project xwiki-platform by xwiki.
the class CategoryPlotFactory method create.
public Plot create(DataSource dataSource, CategoryItemRenderer renderer, ChartParams params) throws GenerateException, DataSourceException {
String dataSeries = params.getString(ChartParams.SERIES);
CategoryAxis domainAxis = new CategoryAxis();
ValueAxis rangeAxis = new NumberAxis();
ChartCustomizer.customizeCategoryAxis(domainAxis, params, ChartParams.AXIS_DOMAIN_PREFIX);
ChartCustomizer.customizeValueAxis(rangeAxis, params, ChartParams.AXIS_RANGE_PREFIX);
Class rendererClass = params.getClass(ChartParams.RENDERER);
ChartCustomizer.customizeCategoryItemRenderer(renderer, params);
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
if ("columns".equals(dataSeries)) {
for (int row = 0; row < dataSource.getRowCount(); row++) {
for (int column = 0; column < dataSource.getColumnCount(); column++) {
dataset.addValue(dataSource.getCell(row, column), dataSource.hasHeaderRow() ? dataSource.getHeaderRowValue(column) : ("Category " + (column + 1)), dataSource.hasHeaderColumn() ? dataSource.getHeaderColumnValue(row) : ("Series " + (row + 1)));
}
}
} else if ("rows".equals(dataSeries)) {
for (int row = 0; row < dataSource.getRowCount(); row++) {
for (int column = 0; column < dataSource.getColumnCount(); column++) {
dataset.addValue(dataSource.getCell(row, column), dataSource.hasHeaderColumn() ? dataSource.getHeaderColumnValue(row) : ("Category " + (row + 1)), dataSource.hasHeaderRow() ? dataSource.getHeaderRowValue(column) : ("Series " + (column + 1)));
}
}
} else {
throw new GenerateException("Invalid series parameter: " + dataSeries);
}
return new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
}
use of com.xpn.xwiki.plugin.charts.exceptions.GenerateException in project xwiki-platform by xwiki.
the class LinePlotFactory method create.
@Override
public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException {
Class rendererClass = params.getClass(ChartParams.RENDERER);
if (rendererClass == null || XYItemRenderer.class.isAssignableFrom(rendererClass)) {
XYItemRenderer renderer;
if (rendererClass != null) {
try {
Constructor ctor = rendererClass.getConstructor(new Class[] {});
renderer = (XYItemRenderer) ctor.newInstance(new Object[] {});
} catch (Throwable e) {
throw new GenerateException(e);
}
} else {
renderer = new XYLineAndShapeRenderer();
}
ChartCustomizer.customizeXYItemRenderer(renderer, params);
return XYPlotFactory.getInstance().create(dataSource, renderer, params);
} else if (CategoryItemRenderer.class.isAssignableFrom(rendererClass)) {
CategoryItemRenderer renderer;
try {
Constructor ctor = rendererClass.getConstructor(new Class[] {});
renderer = (CategoryItemRenderer) ctor.newInstance(new Object[] {});
} catch (Throwable e) {
throw new GenerateException(e);
}
ChartCustomizer.customizeCategoryItemRenderer(renderer, params);
return CategoryPlotFactory.getInstance().create(dataSource, renderer, params);
} else {
throw new GenerateException("Incompatible renderer class: " + rendererClass);
}
}
use of com.xpn.xwiki.plugin.charts.exceptions.GenerateException in project xwiki-platform by xwiki.
the class PiePlotFactory method create.
@Override
public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException {
DefaultPieDataset dataset = new DefaultPieDataset();
String dataSeries = params.getString(ChartParams.SERIES);
if (dataSeries.equals("columns")) {
for (int row = 0; row < dataSource.getRowCount(); row++) {
if (dataSource.hasHeaderColumn()) {
String category = dataSource.getHeaderColumnValue(row);
dataset.setValue(category, dataSource.getCell(row, 0));
} else {
dataset.setValue("Category " + (row + 1), dataSource.getCell(row, 0));
}
}
} else if (dataSeries.equals("rows")) {
for (int column = 0; column < dataSource.getColumnCount(); column++) {
if (dataSource.hasHeaderRow()) {
String category = dataSource.getHeaderRowValue(column);
dataset.setValue(category, dataSource.getCell(0, column));
} else {
dataset.setValue("Category " + (column + 1), dataSource.getCell(0, column));
}
}
} else {
throw new GenerateException("Invalid series parameter:" + dataSeries);
}
Class plotClass = params.getClass(ChartParams.RENDERER);
PiePlot plot;
if (plotClass != null) {
try {
Constructor ctor = plotClass.getConstructor(new Class[] { PieDataset.class });
plot = (PiePlot) ctor.newInstance(new Object[] { dataset });
} catch (Throwable e) {
throw new GenerateException(e);
}
} else {
plot = new PiePlot(dataset);
}
ChartCustomizer.customizePiePlot(plot, params);
return plot;
}
use of com.xpn.xwiki.plugin.charts.exceptions.GenerateException in project xwiki-platform by xwiki.
the class TimePlotFactory method create.
@Override
public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException {
Class rendererClass = params.getClass(ChartParams.RENDERER);
XYItemRenderer renderer;
if (rendererClass != null) {
try {
Constructor ctor = rendererClass.getConstructor(new Class[] {});
renderer = (XYItemRenderer) ctor.newInstance(new Object[] {});
} catch (Throwable e) {
throw new GenerateException(e);
}
} else {
renderer = new XYLineAndShapeRenderer();
}
ChartCustomizer.customizeXYItemRenderer(renderer, params);
DateAxis domainAxis = new DateAxis();
ChartCustomizer.customizeDateAxis(domainAxis, params, ChartParams.AXIS_DOMAIN_PREFIX);
NumberAxis rangeAxis = new NumberAxis();
// override default
rangeAxis.setAutoRangeIncludesZero(false);
ChartCustomizer.customizeNumberAxis(rangeAxis, params, ChartParams.AXIS_RANGE_PREFIX);
XYDataset dataset = TimeSeriesCollectionFactory.getInstance().create(dataSource, params);
XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
ChartCustomizer.customizeXYPlot(plot, params);
return plot;
}
Aggregations