Search in sources :

Example 1 with CustomChartDataFactoryDefault

use of org.devgateway.toolkit.web.excelcharts.util.CustomChartDataFactoryDefault in project ocvn by devgateway.

the class ExcelChartDefault method createWorkbook.

@Override
public Workbook createWorkbook() {
    final ExcelChartSheet excelChartSheet = new ExcelChartSheetDefault(workbook, type.toString());
    final Chart chart = excelChartSheet.createChartAndLegend();
    addCategories(excelChartSheet);
    addValues(excelChartSheet);
    final CustomChartDataFactory customChartDataFactory = new CustomChartDataFactoryDefault();
    final CustomChartData chartData = customChartDataFactory.createChartData(type, title);
    final ChartDataSource<?> categoryDataSource = excelChartSheet.getCategoryChartDataSource();
    final List<ChartDataSource<Number>> valuesDataSource = excelChartSheet.getValuesChartDataSource();
    for (int i = 0; i < valuesDataSource.size(); i++) {
        final ChartDataSource<Number> valueDataSource = valuesDataSource.get(i);
        if (seriesTitle.isEmpty()) {
            chartData.addSeries(categoryDataSource, valueDataSource);
        } else {
            chartData.addSeries(seriesTitle.get(i), categoryDataSource, valueDataSource);
        }
    }
    // we don't have any axis for a pie chart
    if (type.equals(ChartType.pie)) {
        chart.plot(chartData);
    } else {
        // Use a category axis for the bottom axis.
        final ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
        final ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
        leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
        chart.plot(chartData, bottomAxis, leftAxis);
    }
    return workbook;
}
Also used : ChartDataSource(org.apache.poi.ss.usermodel.charts.ChartDataSource) CustomChartDataFactory(org.devgateway.toolkit.web.excelcharts.util.CustomChartDataFactory) CustomChartDataFactoryDefault(org.devgateway.toolkit.web.excelcharts.util.CustomChartDataFactoryDefault) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) ValueAxis(org.apache.poi.ss.usermodel.charts.ValueAxis) Chart(org.apache.poi.ss.usermodel.Chart)

Aggregations

Chart (org.apache.poi.ss.usermodel.Chart)1 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)1 ChartDataSource (org.apache.poi.ss.usermodel.charts.ChartDataSource)1 ValueAxis (org.apache.poi.ss.usermodel.charts.ValueAxis)1 CustomChartDataFactory (org.devgateway.toolkit.web.excelcharts.util.CustomChartDataFactory)1 CustomChartDataFactoryDefault (org.devgateway.toolkit.web.excelcharts.util.CustomChartDataFactoryDefault)1