Search in sources :

Example 6 with SheetBuilder

use of org.apache.poi.ss.util.SheetBuilder 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();
}
Also used : SheetBuilder(org.apache.poi.ss.util.SheetBuilder) ScatterChartData(org.apache.poi.ss.usermodel.charts.ScatterChartData) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) ScatterChartSeries(org.apache.poi.ss.usermodel.charts.ScatterChartSeries) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) Chart(org.apache.poi.ss.usermodel.Chart) Test(org.junit.Test)

Example 7 with SheetBuilder

use of org.apache.poi.ss.util.SheetBuilder in project poi by apache.

the class TestDataSources method testNumericCellDataSource.

public void testNumericCellDataSource() {
    Workbook wb = new HSSFWorkbook();
    Sheet sheet = new SheetBuilder(wb, numericCells).build();
    CellRangeAddress numCellRange = CellRangeAddress.valueOf("A2:E2");
    ChartDataSource<Number> numDataSource = DataSources.fromNumericCellRange(sheet, numCellRange);
    assertTrue(numDataSource.isReference());
    assertTrue(numDataSource.isNumeric());
    assertEquals(numericCells[0].length, numDataSource.getPointCount());
    for (int i = 0; i < numericCells[0].length; ++i) {
        assertEquals(((Number) numericCells[0][i]).doubleValue() * 2, numDataSource.getPointAt(i).doubleValue(), 0.00001);
    }
}
Also used : SheetBuilder(org.apache.poi.ss.util.SheetBuilder) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Aggregations

Sheet (org.apache.poi.ss.usermodel.Sheet)7 Workbook (org.apache.poi.ss.usermodel.Workbook)7 SheetBuilder (org.apache.poi.ss.util.SheetBuilder)7 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)5 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)5 Chart (org.apache.poi.ss.usermodel.Chart)2 ClientAnchor (org.apache.poi.ss.usermodel.ClientAnchor)2 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)2 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 Test (org.junit.Test)2 LineChartData (org.apache.poi.ss.usermodel.charts.LineChartData)1 LineChartSeries (org.apache.poi.ss.usermodel.charts.LineChartSeries)1 ScatterChartData (org.apache.poi.ss.usermodel.charts.ScatterChartData)1 ScatterChartSeries (org.apache.poi.ss.usermodel.charts.ScatterChartSeries)1