Search in sources :

Example 11 with CTPlotArea

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea in project oc-explorer 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.setTitleText(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 12 with CTPlotArea

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea in project poi by apache.

the class TestXSLFChart method testFillChartTemplate.

/**
     * a modified version from POI-examples
     */
@Test
public void testFillChartTemplate() throws IOException {
    // first line is chart title
    String chartTitle = "Apache POI";
    XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument("pie-chart.pptx");
    XSLFSlide slide = pptx.getSlides().get(0);
    // find chart in the slide
    XSLFChart chart = null;
    for (POIXMLDocumentPart part : slide.getRelations()) {
        if (part instanceof XSLFChart) {
            chart = (XSLFChart) part;
            break;
        }
    }
    if (chart == null)
        throw new IllegalStateException("chart not found in the template");
    // embedded Excel workbook that holds the chart data
    POIXMLDocumentPart xlsPart = chart.getRelations().get(0);
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet();
    CTChart ctChart = chart.getCTChart();
    CTPlotArea plotArea = ctChart.getPlotArea();
    CTPieChart pieChart = plotArea.getPieChartArray(0);
    //Pie Chart Series
    CTPieSer ser = pieChart.getSerArray(0);
    // Series Text
    CTSerTx tx = ser.getTx();
    tx.getStrRef().getStrCache().getPtArray(0).setV(chartTitle);
    sheet.createRow(0).createCell(1).setCellValue(chartTitle);
    String titleRef = new CellReference(sheet.getSheetName(), 0, 1, true, true).formatAsString();
    tx.getStrRef().setF(titleRef);
    // Category Axis Data
    CTAxDataSource cat = ser.getCat();
    CTStrData strData = cat.getStrRef().getStrCache();
    // Values
    CTNumDataSource valSrc = ser.getVal();
    CTNumData numData = valSrc.getNumRef().getNumCache();
    // unset old axis text
    strData.setPtArray(null);
    // unset old values
    numData.setPtArray(null);
    Map<String, Double> pieModel = new LinkedHashMap<String, Double>();
    pieModel.put("First", 1.0);
    pieModel.put("Second", 3.0);
    pieModel.put("Third", 4.0);
    // set model
    int idx = 0;
    int rownum = 1;
    for (String key : pieModel.keySet()) {
        double val = pieModel.get(key);
        CTNumVal numVal = numData.addNewPt();
        numVal.setIdx(idx);
        numVal.setV("" + val);
        CTStrVal sVal = strData.addNewPt();
        sVal.setIdx(idx);
        sVal.setV(key);
        idx++;
        XSSFRow row = sheet.createRow(rownum++);
        row.createCell(0).setCellValue(key);
        row.createCell(1).setCellValue(val);
    }
    numData.getPtCount().setVal(idx);
    strData.getPtCount().setVal(idx);
    String numDataRange = new CellRangeAddress(1, rownum - 1, 1, 1).formatAsString(sheet.getSheetName(), true);
    valSrc.getNumRef().setF(numDataRange);
    String axisDataRange = new CellRangeAddress(1, rownum - 1, 0, 0).formatAsString(sheet.getSheetName(), true);
    cat.getStrRef().setF(axisDataRange);
    // updated the embedded workbook with the data
    OutputStream xlsOut = xlsPart.getPackagePart().getOutputStream();
    wb.write(xlsOut);
    xlsOut.close();
    wb.close();
}
Also used : CTStrData(org.openxmlformats.schemas.drawingml.x2006.chart.CTStrData) CTNumDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) OutputStream(java.io.OutputStream) CTPlotArea(org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea) CTSerTx(org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx) CellReference(org.apache.poi.ss.util.CellReference) CTAxDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource) LinkedHashMap(java.util.LinkedHashMap) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) CTNumData(org.openxmlformats.schemas.drawingml.x2006.chart.CTNumData) CTPieChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTPieChart) CTPieSer(org.openxmlformats.schemas.drawingml.x2006.chart.CTPieSer) CTStrVal(org.openxmlformats.schemas.drawingml.x2006.chart.CTStrVal) CTNumVal(org.openxmlformats.schemas.drawingml.x2006.chart.CTNumVal) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Test(org.junit.Test)

Example 13 with CTPlotArea

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea in project poi by apache.

the class XSSFChart method createChart.

/**
	 * Construct a new CTChartSpace bean.
	 * By default, it's just an empty placeholder for chart objects.
	 *
	 * @return a new CTChartSpace bean
	 */
private void createChart() {
    chartSpace = CTChartSpace.Factory.newInstance();
    chart = chartSpace.addNewChart();
    CTPlotArea plotArea = chart.addNewPlotArea();
    plotArea.addNewLayout();
    chart.addNewPlotVisOnly().setVal(true);
    CTPrintSettings printSettings = chartSpace.addNewPrintSettings();
    printSettings.addNewHeaderFooter();
    CTPageMargins pageMargins = printSettings.addNewPageMargins();
    pageMargins.setB(0.75);
    pageMargins.setL(0.70);
    pageMargins.setR(0.70);
    pageMargins.setT(0.75);
    pageMargins.setHeader(0.30);
    pageMargins.setFooter(0.30);
    printSettings.addNewPageSetup();
}
Also used : CTPrintSettings(org.openxmlformats.schemas.drawingml.x2006.chart.CTPrintSettings) CTPlotArea(org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea) CTPageMargins(org.openxmlformats.schemas.drawingml.x2006.chart.CTPageMargins)

Example 14 with CTPlotArea

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea 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 15 with CTPlotArea

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea 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)

Aggregations

CTPlotArea (org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea)22 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)18 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)16 CustomChartSeries (org.devgateway.toolkit.web.excelcharts.CustomChartSeries)14 CTValAx (org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx)10 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)4 CTCatAx (org.openxmlformats.schemas.drawingml.x2006.chart.CTCatAx)4 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)4 CTPieChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTPieChart)4 CTBarChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTBarChart)3 CTLineChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart)3 CTScatterChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterChart)3 AddTrace (com.google.firebase.perf.metrics.AddTrace)2 SpreadsheetUtils.getCellRangeAddress (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getCellRangeAddress)2 SpreadsheetUtils.getMetricForChart (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getMetricForChart)2 SpreadsheetUtils.getStringForCell (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getStringForCell)2 PreferencesUtilsKt.setShouldShowExportHint (com.supercilex.robotscouter.util.PreferencesUtilsKt.setShouldShowExportHint)2 PreferencesUtilsKt.shouldShowExportHint (com.supercilex.robotscouter.util.PreferencesUtilsKt.shouldShowExportHint)2 OutputStream (java.io.OutputStream)2 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)2