Search in sources :

Example 21 with XSSFChart

use of org.apache.poi.xssf.usermodel.XSSFChart in project poi by apache.

the class TestXSSFChartTitle method testNewChart.

@Test
public void testNewChart() throws IOException {
    Workbook wb = createWorkbookWithChart();
    XSSFChart chart = getChartFromWorkbook(wb, "linechart");
    assertNotNull(chart);
    assertNull(chart.getTitleText());
    final String myTitle = "My chart title";
    chart.setTitleText(myTitle);
    XSSFRichTextString queryTitle = chart.getTitleText();
    assertNotNull(queryTitle);
    assertEquals(myTitle, queryTitle.toString());
    final String myTitleFormula = "1 & \" and \" & 2";
    chart.setTitleFormula(myTitleFormula);
    // setting formula should unset text, but since there is a formula, returns an empty string
    assertEquals("", chart.getTitleText().toString());
    String titleFormula = chart.getTitleFormula();
    assertNotNull(titleFormula);
    assertEquals(myTitleFormula, titleFormula);
    wb.close();
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 22 with XSSFChart

use of org.apache.poi.xssf.usermodel.XSSFChart in project ocvn by devgateway.

the class XSSFBarChartData method fillChart.

@Override
public void fillChart(final Chart chart, final ChartAxis... axis) {
    if (!(chart instanceof XSSFChart)) {
        throw new IllegalArgumentException("Chart must be instance of XSSFChart");
    }
    final XSSFChart xssfChart = (XSSFChart) chart;
    final CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
    final CTBarChart barChart = plotArea.addNewBarChart();
    barChart.addNewVaryColors().setVal(false);
    // set bars orientation
    barChart.addNewBarDir().setVal(barDir);
    xssfChart.setTitle(this.title);
    CTValAx[] ctValAx = plotArea.getValAxArray();
    if (ctValAx.length != 0) {
        ctValAx[0].addNewMajorGridlines().addNewSpPr().addNewSolidFill();
        ctValAx[0].getCrossBetween().setVal(STCrossBetween.BETWEEN);
    }
    for (CustomChartSeries s : series) {
        s.addToChart(barChart);
    }
    for (ChartAxis ax : axis) {
        barChart.addNewAxId().setVal(ax.getId());
    }
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) CTValAx(org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx) CustomChartSeries(org.devgateway.toolkit.web.excelcharts.CustomChartSeries) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) CTPlotArea(org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea) CTBarChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTBarChart)

Example 23 with XSSFChart

use of org.apache.poi.xssf.usermodel.XSSFChart in project ocvn by devgateway.

the class XSSFBubbleChartData method fillChart.

@Override
public void fillChart(final Chart chart, final ChartAxis... axis) {
    if (!(chart instanceof XSSFChart)) {
        throw new IllegalArgumentException("Chart must be instance of XSSFChart");
    }
    final XSSFChart xssfChart = (XSSFChart) chart;
    final CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
    final CTBubbleChart bubbleChart = plotArea.addNewBubbleChart();
    for (CustomChartSeries s : series) {
        s.addToChart(bubbleChart);
    }
    for (ChartAxis ax : axis) {
        bubbleChart.addNewAxId().setVal(ax.getId());
    }
    xssfChart.setTitle(this.title);
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) CustomChartSeries(org.devgateway.toolkit.web.excelcharts.CustomChartSeries) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) CTPlotArea(org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea) CTBubbleChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTBubbleChart)

Example 24 with XSSFChart

use of org.apache.poi.xssf.usermodel.XSSFChart in project ocvn by devgateway.

the class XSSFPieChartData method fillChart.

@Override
public void fillChart(final Chart chart, final ChartAxis... axis) {
    if (!(chart instanceof XSSFChart)) {
        throw new IllegalArgumentException("Chart must be instance of XSSFChart");
    }
    final XSSFChart xssfChart = (XSSFChart) chart;
    final CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
    final CTPieChart pieChart = plotArea.addNewPieChart();
    pieChart.addNewVaryColors().setVal(true);
    xssfChart.setTitle(this.title);
    for (CustomChartSeries s : series) {
        s.addToChart(pieChart);
    }
}
Also used : CTPieChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTPieChart) XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) CustomChartSeries(org.devgateway.toolkit.web.excelcharts.CustomChartSeries) CTPlotArea(org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea)

Example 25 with XSSFChart

use of org.apache.poi.xssf.usermodel.XSSFChart in project ocvn by devgateway.

the class TotalCancelledTendersExcelControllerTest method cancelledFundingExcelChart.

@Test
public void cancelledFundingExcelChart() throws Exception {
    LangYearFilterPagingRequest filter = getLangYearFilterMockRequest();
    totalCancelledTendersExcelController.cancelledFundingExcelChart(filter, mockHttpServletResponse);
    final byte[] responseOutput = mockHttpServletResponse.getContentAsByteArray();
    final Workbook workbook = new XSSFWorkbook(new ByteArrayInputStream(responseOutput));
    Assert.assertNotNull(workbook);
    final Sheet sheet = workbook.getSheet(ChartType.area.toString());
    Assert.assertNotNull("check chart type, sheet name should be the same as the type", sheet);
    final XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch();
    final List<XSSFChart> charts = drawing.getCharts();
    Assert.assertEquals("number of charts", 1, charts.size());
    final XSSFChart chart = charts.get(0);
    Assert.assertEquals("chart title", translationService.getValue(filter.getLanguage(), "charts:cancelledAmounts:title"), chart.getTitle().getString());
    final List<? extends XSSFChartAxis> axis = chart.getAxis();
    Assert.assertEquals("number of axis", 2, axis.size());
    final CTChart ctChart = chart.getCTChart();
    Assert.assertEquals("Check if we have 1 area chart", 1, ctChart.getPlotArea().getAreaChartArray().length);
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) LangYearFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.LangYearFilterPagingRequest) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) ByteArrayInputStream(java.io.ByteArrayInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing) Test(org.junit.Test)

Aggregations

XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)32 Workbook (org.apache.poi.ss.usermodel.Workbook)19 Test (org.junit.Test)19 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)18 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)18 Sheet (org.apache.poi.ss.usermodel.Sheet)17 XSSFDrawing (org.apache.poi.xssf.usermodel.XSSFDrawing)16 ByteArrayInputStream (java.io.ByteArrayInputStream)14 LangYearFilterPagingRequest (org.devgateway.ocds.web.rest.controller.request.LangYearFilterPagingRequest)13 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)11 CTPlotArea (org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea)11 CustomChartSeries (org.devgateway.toolkit.web.excelcharts.CustomChartSeries)7 CTValAx (org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx)5 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 Chart (org.apache.poi.ss.usermodel.Chart)3 RichTextString (org.apache.poi.ss.usermodel.RichTextString)3