Search in sources :

Example 1 with ChartDataSource

use of org.apache.poi.ss.usermodel.charts.ChartDataSource in project ocvn by devgateway.

the class ExcelChartSheetDefault method getChartDataSource.

private ChartDataSource getChartDataSource(final int row) {
    final int lastCellNum = excelSheet.getRow(row).getLastCellNum() - 1;
    final CellRangeAddress cellRangeAddress = new CellRangeAddress(row, row, 0, lastCellNum);
    final ChartDataSource chartDataSource;
    if (row == 0) {
        chartDataSource = DataSources.fromStringCellRange(excelSheet, cellRangeAddress);
    } else {
        chartDataSource = DataSources.fromNumericCellRange(excelSheet, cellRangeAddress);
    }
    return chartDataSource;
}
Also used : ChartDataSource(org.apache.poi.ss.usermodel.charts.ChartDataSource) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Example 2 with ChartDataSource

use of org.apache.poi.ss.usermodel.charts.ChartDataSource in project ocvn by devgateway.

the class ExcelChartSheetDefaultTest method getCategoryChartDataSource.

@Test
public void getCategoryChartDataSource() throws Exception {
    final ExcelChartSheet excelChartSheet = new ExcelChartSheetDefault(workbook, ChartType.barcol.toString());
    addCategories(excelChartSheet);
    ChartDataSource categoryChartDataSource = excelChartSheet.getCategoryChartDataSource();
    Assert.assertEquals("check count of categories", 5, categoryChartDataSource.getPointCount());
    Assert.assertEquals("check first category", "cat 1", categoryChartDataSource.getPointAt(0));
    Assert.assertEquals("check last category", "cat 5", categoryChartDataSource.getPointAt(4));
}
Also used : ChartDataSource(org.apache.poi.ss.usermodel.charts.ChartDataSource) Test(org.junit.Test)

Example 3 with ChartDataSource

use of org.apache.poi.ss.usermodel.charts.ChartDataSource 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)

Example 4 with ChartDataSource

use of org.apache.poi.ss.usermodel.charts.ChartDataSource in project oc-explorer 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)

Example 5 with ChartDataSource

use of org.apache.poi.ss.usermodel.charts.ChartDataSource in project oc-explorer by devgateway.

the class ExcelChartSheetDefault method getChartDataSource.

private ChartDataSource getChartDataSource(final int row) {
    final int lastCellNum = excelSheet.getRow(row).getLastCellNum() - 1;
    final CellRangeAddress cellRangeAddress = new CellRangeAddress(row, row, 0, lastCellNum);
    final ChartDataSource chartDataSource;
    if (row == 0) {
        chartDataSource = DataSources.fromStringCellRange(excelSheet, cellRangeAddress);
    } else {
        chartDataSource = DataSources.fromNumericCellRange(excelSheet, cellRangeAddress);
    }
    return chartDataSource;
}
Also used : ChartDataSource(org.apache.poi.ss.usermodel.charts.ChartDataSource) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Aggregations

ChartDataSource (org.apache.poi.ss.usermodel.charts.ChartDataSource)6 Chart (org.apache.poi.ss.usermodel.Chart)2 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)2 ValueAxis (org.apache.poi.ss.usermodel.charts.ValueAxis)2 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)2 CustomChartDataFactory (org.devgateway.toolkit.web.excelcharts.util.CustomChartDataFactory)2 CustomChartDataFactoryDefault (org.devgateway.toolkit.web.excelcharts.util.CustomChartDataFactoryDefault)2 Test (org.junit.Test)2