Search in sources :

Example 11 with Chart

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();
}
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 12 with Chart

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();
}
Also used : ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ChartLegend(org.apache.poi.ss.usermodel.charts.ChartLegend) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Chart(org.apache.poi.ss.usermodel.Chart) Test(org.junit.Test)

Example 13 with Chart

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;
}
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 14 with Chart

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;
}
Also used : Drawing(org.apache.poi.ss.usermodel.Drawing) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) ChartLegend(org.apache.poi.ss.usermodel.charts.ChartLegend) Chart(org.apache.poi.ss.usermodel.Chart)

Example 15 with 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);
}
Also used : Chart(org.apache.poi.ss.usermodel.Chart) Test(org.junit.Test)

Aggregations

Chart (org.apache.poi.ss.usermodel.Chart)15 ClientAnchor (org.apache.poi.ss.usermodel.ClientAnchor)11 Sheet (org.apache.poi.ss.usermodel.Sheet)10 ChartLegend (org.apache.poi.ss.usermodel.charts.ChartLegend)9 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)9 Workbook (org.apache.poi.ss.usermodel.Workbook)8 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)8 Row (org.apache.poi.ss.usermodel.Row)6 ValueAxis (org.apache.poi.ss.usermodel.charts.ValueAxis)6 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)6 Test (org.junit.Test)6 Cell (org.apache.poi.ss.usermodel.Cell)5 LineChartData (org.apache.poi.ss.usermodel.charts.LineChartData)5 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)4 AddTrace (com.google.firebase.perf.metrics.AddTrace)3 SpreadsheetUtils.getCellRangeAddress (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getCellRangeAddress)3 SpreadsheetUtils.getMetricForChart (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getMetricForChart)3 PreferencesUtilsKt.setShouldShowExportHint (com.supercilex.robotscouter.util.PreferencesUtilsKt.setShouldShowExportHint)3 PreferencesUtilsKt.shouldShowExportHint (com.supercilex.robotscouter.util.PreferencesUtilsKt.shouldShowExportHint)3 Drawing (org.apache.poi.ss.usermodel.Drawing)3