use of org.apache.poi.ss.usermodel.Chart in project poi by apache.
the class TestXSSFScatterChartData method testOneSeriePlot.
@Test
public void testOneSeriePlot() throws IOException {
Workbook wb = new XSSFWorkbook();
Sheet sheet = new SheetBuilder(wb, plotData).build();
Drawing<?> drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
Chart chart = drawing.createChart(anchor);
ChartAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
ChartAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
ScatterChartData scatterChartData = chart.getChartDataFactory().createScatterChartData();
ChartDataSource<String> xs = DataSources.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
ChartDataSource<Number> ys = DataSources.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
ScatterChartSeries series = scatterChartData.addSerie(xs, ys);
assertNotNull(series);
assertEquals(1, scatterChartData.getSeries().size());
assertTrue(scatterChartData.getSeries().contains(series));
chart.plot(scatterChartData, bottomAxis, leftAxis);
wb.close();
}
use of org.apache.poi.ss.usermodel.Chart in project poi by apache.
the class TestXSSFChartLegend method test_setOverlay_defaultChartLegend_expectOverlayInitialValueSetToFalse.
@Test
public void test_setOverlay_defaultChartLegend_expectOverlayInitialValueSetToFalse() throws IOException {
// Arrange
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
Drawing<?> drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
Chart chart = drawing.createChart(anchor);
ChartLegend legend = chart.getOrCreateLegend();
// Act
// Assert
assertFalse(legend.isOverlay());
wb.close();
}
use of org.apache.poi.ss.usermodel.Chart 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.Chart in project ocvn by devgateway.
the class ExcelChartSheetDefault method createChartAndLegend.
/**
* Creates a chart and also attaches a legend to it.
*/
@Override
public Chart createChartAndLegend() {
final Drawing drawing = excelSheet.createDrawingPatriarch();
final ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 15, 25);
final Chart chart = drawing.createChart(anchor);
final ChartLegend legend = chart.getOrCreateLegend();
legend.setPosition(LegendPosition.BOTTOM);
return chart;
}
use of org.apache.poi.ss.usermodel.Chart in project ocvn by devgateway.
the class ExcelChartSheetDefaultTest method createChartAndLegend.
@Test
public void createChartAndLegend() throws Exception {
final ExcelChartSheet excelChartSheet = new ExcelChartSheetDefault(workbook, ChartType.pie.toString());
Chart chart = excelChartSheet.createChartAndLegend();
Assert.assertNotNull(chart);
}
Aggregations