how to generate stackedBar chart using apache poi

2019-08-16 06:03发布

I need a sample code in Java, currently I am able to draw line and pie charts charts after reading values from sheet, and I also want to generate a StackedBar chart.

I added a snipplet of code for pie chart which I have attempted which is for .ppt format. I want the same in excel for stackedBar chart in java.


String[] categories = listCategories.toArray(new String[listCategories.size()]);
            Double[] values = listValues.toArray(new Double[listValues.size()]);

            final int numOfPoints = categories.length;
            final String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
            final String valuesDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 1, 1));
            final XDDFDataSource<?> categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange);
            final XDDFNumericalDataSource<? extends Number> valuesData = XDDFDataSourcesFactory.fromArray(values, valuesDataRange);

            XDDFPieChartData.Series firstSeries = (XDDFPieChartData.Series) pie.getSeries().get(0);
            firstSeries.replaceData(categoriesData, valuesData);
            firstSeries.setTitle(chartTitle, chart.setSheetTitle(chartTitle, 0));
            firstSeries.setExplosion(25);
            chart.plot(pie);

0条回答
登录 后发表回答