use of com.xpn.xwiki.plugin.charts.plots.PlotFactory in project xwiki-platform by xwiki.
the class ChartingPlugin method generateChart.
public Chart generateChart(ChartParams params, XWikiContext context) throws GenerateException {
try {
// Obtain the corresponding data source and wrap it into a data source object
DataSource dataSource = MainDataSourceFactory.getInstance().create(params.getMap(ChartParams.SOURCE), context);
String type = params.getString(ChartParams.TYPE);
Plot plot;
try {
String factoryClassName = ChartingPlugin.class.getPackage().getName() + ".plots." + Character.toUpperCase(type.charAt(0)) + type.toLowerCase().substring(1) + "PlotFactory";
Class factoryClass = Class.forName(factoryClassName);
Method method = factoryClass.getMethod("getInstance", new Class[] {});
PlotFactory factory = (PlotFactory) method.invoke(null, new Object[] {});
plot = factory.create(dataSource, params);
} catch (InvocationTargetException e) {
throw new GenerateException(e.getTargetException());
} catch (Throwable e) {
throw new GenerateException(e);
}
ChartCustomizer.customizePlot(plot, params);
JFreeChart jfchart = new JFreeChart(plot);
ChartCustomizer.customizeChart(jfchart, params);
return generatePngChart(jfchart, params, context);
} catch (IOException ioe) {
throw new GenerateException(ioe);
} catch (DataSourceException dse) {
throw new GenerateException(dse);
}
}
Aggregations