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;
}
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));
}
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;
}
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;
}
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;
}
Aggregations