Search in sources :

Example 1 with DataSource

use of com.xpn.xwiki.plugin.charts.source.DataSource 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);
    }
}
Also used : PlotFactory(com.xpn.xwiki.plugin.charts.plots.PlotFactory) Plot(org.jfree.chart.plot.Plot) Method(java.lang.reflect.Method) IOException(java.io.IOException) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException) InvocationTargetException(java.lang.reflect.InvocationTargetException) JFreeChart(org.jfree.chart.JFreeChart) DataSource(com.xpn.xwiki.plugin.charts.source.DataSource) DataSourceException(com.xpn.xwiki.plugin.charts.exceptions.DataSourceException)

Aggregations

DataSourceException (com.xpn.xwiki.plugin.charts.exceptions.DataSourceException)1 GenerateException (com.xpn.xwiki.plugin.charts.exceptions.GenerateException)1 PlotFactory (com.xpn.xwiki.plugin.charts.plots.PlotFactory)1 DataSource (com.xpn.xwiki.plugin.charts.source.DataSource)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 JFreeChart (org.jfree.chart.JFreeChart)1 Plot (org.jfree.chart.plot.Plot)1