Search in sources :

Example 1 with CTLineChart

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

the class XSSFLineChartData method fillChart.

public void fillChart(Chart chart, ChartAxis... axis) {
    if (!(chart instanceof XSSFChart)) {
        throw new IllegalArgumentException("Chart must be instance of XSSFChart");
    }
    XSSFChart xssfChart = (XSSFChart) chart;
    CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
    CTLineChart lineChart = plotArea.addNewLineChart();
    lineChart.addNewVaryColors().setVal(false);
    for (Series s : series) {
        s.addToChart(lineChart);
    }
    for (ChartAxis ax : axis) {
        lineChart.addNewAxId().setVal(ax.getId());
    }
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) CTLineChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart) LineChartSeries(org.apache.poi.ss.usermodel.charts.LineChartSeries) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) CTPlotArea(org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea)

Example 2 with CTLineChart

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart in project ocvn by devgateway.

the class XSSFLineChartData 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 CTLineChart lineChart = plotArea.addNewLineChart();
    lineChart.addNewVaryColors().setVal(false);
    for (CustomChartSeries s : series) {
        s.addToChart(lineChart);
    }
    for (ChartAxis ax : axis) {
        lineChart.addNewAxId().setVal(ax.getId());
    }
    xssfChart.setTitle(this.title);
    // add grid lines
    CTCatAx[] ctCatAx = plotArea.getCatAxArray();
    if (ctCatAx.length != 0) {
        ctCatAx[0].addNewMajorGridlines().addNewSpPr().addNewSolidFill();
    }
    CTValAx[] ctValAx = plotArea.getValAxArray();
    if (ctValAx.length != 0) {
        ctValAx[0].addNewMajorGridlines().addNewSpPr().addNewSolidFill();
    }
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) CTLineChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart) CustomChartSeries(org.devgateway.toolkit.web.excelcharts.CustomChartSeries) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) CTValAx(org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx) CTPlotArea(org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea) CTCatAx(org.openxmlformats.schemas.drawingml.x2006.chart.CTCatAx)

Example 3 with CTLineChart

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart in project ocvn by devgateway.

the class XSSFLineChartData method createNewSerie.

@Override
protected CustomChartSeries createNewSerie(final int id, final int order, final ChartDataSource<?> categories, final ChartDataSource<? extends Number> values) {
    return new AbstractSeries(id, order, categories, values) {

        @Override
        public void addToChart(final XmlObject ctChart) {
            final CTLineChart ctLineChart = (CTLineChart) ctChart;
            final CTLineSer ctLineSer = ctLineChart.addNewSer();
            ctLineSer.addNewIdx().setVal(this.id);
            ctLineSer.addNewOrder().setVal(this.order);
            // No marker symbol on the chart line.
            ctLineSer.addNewMarker().addNewSymbol().setVal(STMarkerStyle.CIRCLE);
            final CTAxDataSource catDS = ctLineSer.addNewCat();
            XSSFChartUtil.buildAxDataSource(catDS, this.categories);
            final CTNumDataSource valueDS = ctLineSer.addNewVal();
            XSSFChartUtil.buildNumDataSource(valueDS, this.values);
            if (isTitleSet()) {
                ctLineSer.setTx(getCTSerTx());
            }
        }
    };
}
Also used : CTLineChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart) CTNumDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource) CTLineSer(org.openxmlformats.schemas.drawingml.x2006.chart.CTLineSer) XmlObject(org.apache.xmlbeans.XmlObject) CTAxDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource)

Example 4 with CTLineChart

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart in project oc-explorer by devgateway.

the class ExcelChartDefaultTest method createWorkbook.

@Test
public void createWorkbook() throws Exception {
    final ExcelChart excelChart = new ExcelChartDefault("line chart", ChartType.line, CATEGORIES, VALUES);
    excelChart.configureSeriesTitle(Arrays.asList("foo", "bar"));
    final Workbook workbook = excelChart.createWorkbook();
    Assert.assertNotNull(workbook);
    final Sheet sheet = workbook.getSheet(ChartType.line.toString());
    Assert.assertNotNull(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", "line chart", chart.getTitleText().getString());
    final CTChart ctChart = chart.getCTChart();
    Assert.assertEquals("We should not have any area chart", 0, ctChart.getPlotArea().getAreaChartArray().length);
    Assert.assertEquals("Check if we have 1 line chart", 1, ctChart.getPlotArea().getLineChartArray().length);
    Assert.assertEquals("Check that we have a legend and that it's position is bottom", STLegendPos.B, ctChart.getLegend().getLegendPos().getVal());
    // check the actual chart data
    final CTLineChart ctLineChart = ctChart.getPlotArea().getLineChartArray()[0];
    final CTLineSer[] ctLineSer = ctLineChart.getSerArray();
    Assert.assertEquals("Check number of CTLineSer", 2, ctLineSer.length);
    Assert.assertEquals("check first series title", "foo", ctLineSer[0].getTx().getV());
    Assert.assertEquals("check second series title", "bar", ctLineSer[1].getTx().getV());
    final CTAxDataSource cat1 = ctLineSer[0].getCat();
    Assert.assertEquals("check first category", "cat 1", cat1.getStrRef().getStrCache().getPtArray()[0].getV());
    Assert.assertEquals("check last category", "cat 5", cat1.getStrRef().getStrCache().getPtArray()[4].getV());
    final CTAxDataSource cat2 = ctLineSer[1].getCat();
    Assert.assertEquals("check first category", "cat 1", cat2.getStrRef().getStrCache().getPtArray()[0].getV());
    Assert.assertEquals("check last category", "cat 5", cat2.getStrRef().getStrCache().getPtArray()[4].getV());
    final CTNumDataSource val1 = ctLineSer[0].getVal();
    Assert.assertEquals("check first value", "5.0", val1.getNumRef().getNumCache().getPtArray()[0].getV());
    Assert.assertEquals("check last value", "6.0", val1.getNumRef().getNumCache().getPtArray()[4].getV());
    final CTNumDataSource val2 = ctLineSer[1].getVal();
    Assert.assertEquals("check first value", "20.0", val2.getNumRef().getNumCache().getPtArray()[0].getV());
    Assert.assertEquals("check last value", "14.0", val2.getNumRef().getNumCache().getPtArray()[4].getV());
    final List<? extends XSSFChartAxis> axis = chart.getAxis();
    Assert.assertEquals("number of axis", 2, axis.size());
    Assert.assertTrue("category axis", axis.get(0) instanceof XSSFCategoryAxis);
    Assert.assertTrue("value axis", axis.get(1) instanceof XSSFValueAxis);
}
Also used : CTNumDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource) XSSFCategoryAxis(org.apache.poi.xssf.usermodel.charts.XSSFCategoryAxis) XSSFValueAxis(org.apache.poi.xssf.usermodel.charts.XSSFValueAxis) Workbook(org.apache.poi.ss.usermodel.Workbook) CTAxDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource) XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) CTLineChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) CTLineSer(org.openxmlformats.schemas.drawingml.x2006.chart.CTLineSer) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing) Test(org.junit.Test)

Example 5 with CTLineChart

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart in project ocvn by devgateway.

the class ExcelChartDefaultTest method createWorkbook.

@Test
public void createWorkbook() throws Exception {
    final ExcelChart excelChart = new ExcelChartDefault("line chart", ChartType.line, CATEGORIES, VALUES);
    excelChart.configureSeriesTitle(Arrays.asList("foo", "bar"));
    final Workbook workbook = excelChart.createWorkbook();
    Assert.assertNotNull(workbook);
    final Sheet sheet = workbook.getSheet(ChartType.line.toString());
    Assert.assertNotNull(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", "line chart", chart.getTitle().getString());
    final CTChart ctChart = chart.getCTChart();
    Assert.assertEquals("We should not have any area chart", 0, ctChart.getPlotArea().getAreaChartArray().length);
    Assert.assertEquals("Check if we have 1 line chart", 1, ctChart.getPlotArea().getLineChartArray().length);
    Assert.assertEquals("Check that we have a legend and that it's position is bottom", STLegendPos.B, ctChart.getLegend().getLegendPos().getVal());
    // check the actual chart data
    final CTLineChart ctLineChart = ctChart.getPlotArea().getLineChartArray()[0];
    final CTLineSer[] ctLineSer = ctLineChart.getSerArray();
    Assert.assertEquals("Check number of CTLineSer", 2, ctLineSer.length);
    Assert.assertEquals("check first series title", "foo", ctLineSer[0].getTx().getV());
    Assert.assertEquals("check second series title", "bar", ctLineSer[1].getTx().getV());
    final CTAxDataSource cat1 = ctLineSer[0].getCat();
    Assert.assertEquals("check first category", "cat 1", cat1.getStrRef().getStrCache().getPtArray()[0].getV());
    Assert.assertEquals("check last category", "cat 5", cat1.getStrRef().getStrCache().getPtArray()[4].getV());
    final CTAxDataSource cat2 = ctLineSer[1].getCat();
    Assert.assertEquals("check first category", "cat 1", cat2.getStrRef().getStrCache().getPtArray()[0].getV());
    Assert.assertEquals("check last category", "cat 5", cat2.getStrRef().getStrCache().getPtArray()[4].getV());
    final CTNumDataSource val1 = ctLineSer[0].getVal();
    Assert.assertEquals("check first value", "5.0", val1.getNumRef().getNumCache().getPtArray()[0].getV());
    Assert.assertEquals("check last value", "6.0", val1.getNumRef().getNumCache().getPtArray()[4].getV());
    final CTNumDataSource val2 = ctLineSer[1].getVal();
    Assert.assertEquals("check first value", "20.0", val2.getNumRef().getNumCache().getPtArray()[0].getV());
    Assert.assertEquals("check last value", "14.0", val2.getNumRef().getNumCache().getPtArray()[4].getV());
    final List<? extends XSSFChartAxis> axis = chart.getAxis();
    Assert.assertEquals("number of axis", 2, axis.size());
    Assert.assertTrue("category axis", axis.get(0) instanceof XSSFCategoryAxis);
    Assert.assertTrue("value axis", axis.get(1) instanceof XSSFValueAxis);
}
Also used : CTNumDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource) XSSFCategoryAxis(org.apache.poi.xssf.usermodel.charts.XSSFCategoryAxis) XSSFValueAxis(org.apache.poi.xssf.usermodel.charts.XSSFValueAxis) Workbook(org.apache.poi.ss.usermodel.Workbook) CTAxDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource) XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) CTLineChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) CTLineSer(org.openxmlformats.schemas.drawingml.x2006.chart.CTLineSer) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing) Test(org.junit.Test)

Aggregations

CTLineChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart)7 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)5 CTAxDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource)4 CTLineSer (org.openxmlformats.schemas.drawingml.x2006.chart.CTLineSer)4 CTNumDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource)4 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)3 CTPlotArea (org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea)3 Sheet (org.apache.poi.ss.usermodel.Sheet)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 XSSFDrawing (org.apache.poi.xssf.usermodel.XSSFDrawing)2 XSSFCategoryAxis (org.apache.poi.xssf.usermodel.charts.XSSFCategoryAxis)2 XSSFValueAxis (org.apache.poi.xssf.usermodel.charts.XSSFValueAxis)2 XmlObject (org.apache.xmlbeans.XmlObject)2 CustomChartSeries (org.devgateway.toolkit.web.excelcharts.CustomChartSeries)2 Test (org.junit.Test)2 CTCatAx (org.openxmlformats.schemas.drawingml.x2006.chart.CTCatAx)2 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)2 CTValAx (org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx)2 LineChartSeries (org.apache.poi.ss.usermodel.charts.LineChartSeries)1