Search in sources :

Example 1 with GenerateException

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);
    }
}
Also used : CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) Constructor(java.lang.reflect.Constructor) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException)

Example 2 with GenerateException

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);
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ValueAxis(org.jfree.chart.axis.ValueAxis) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 3 with GenerateException

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);
    }
}
Also used : CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) Constructor(java.lang.reflect.Constructor) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException)

Example 4 with GenerateException

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;
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) Constructor(java.lang.reflect.Constructor) PiePlot(org.jfree.chart.plot.PiePlot) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException)

Example 5 with GenerateException

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;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) Constructor(java.lang.reflect.Constructor) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) XYDataset(org.jfree.data.xy.XYDataset) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException)

Aggregations

GenerateException (com.xpn.xwiki.plugin.charts.exceptions.GenerateException)10 Constructor (java.lang.reflect.Constructor)6 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)4 CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)3 DataSourceException (com.xpn.xwiki.plugin.charts.exceptions.DataSourceException)2 NumberAxis (org.jfree.chart.axis.NumberAxis)2 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)2 PlotFactory (com.xpn.xwiki.plugin.charts.plots.PlotFactory)1 DataSource (com.xpn.xwiki.plugin.charts.source.DataSource)1 SVGPlugin (com.xpn.xwiki.plugin.svg.SVGPlugin)1 Rectangle2D (java.awt.geom.Rectangle2D)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 SVGConverterException (org.apache.batik.apps.rasterizer.SVGConverterException)1 GenericDOMImplementation (org.apache.batik.dom.GenericDOMImplementation)1