how to generate stackedBar chart using apache poi 4.0 XDDFChartData, XDDFBarChartData ; in excel sheet using java, i dont want to use jfree

本小妞迷上赌 提交于 2019-12-11 17:18:44

问题


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);

来源:https://stackoverflow.com/questions/54901830/how-to-generate-stackedbar-chart-using-apache-poi-4-0-xddfchartdata-xddfbarchar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!