Hi @Andrey_Potapov!
Thank you,
I’m using the 21.4 version (the last one).
Here is the code to reproduce the fact:
@Test
void doughnutChartTest() throws Exception {
Presentation pt = new Presentation(getClass().getResource("/templates/doughnut-chart-test.pptx").getPath());
ISlide slide = pt.getSlides().get_Item(0);
for (IShape shape : slide.getShapes()) {
if (shape instanceof IChart) {
IChart ptChart = (IChart) shape;
IChartDataWorkbook chartData = ptChart.getChartData().getChartDataWorkbook();
if (chartData.getCell(0, 0, 0).getValue().toString().equals("{{CHART_TEST}}")) {
// Clear chart sample data:
chartData.clear(0);
ptChart.getChartData().getSeries().clear();
ptChart.getChartData().getCategories().clear();
// Fill chart with new data:
ptChart.getChartData().getSeries().add(chartData.getCell(0, 0, 1, "Number of"), ptChart.getType());
IChartSeries series = ptChart.getChartData().getSeries().get_Item(0);
series.getDataPoints().addDataPointForDoughnutSeries(chartData.getCell(0, 1, 1, 5));
series.getDataPoints().addDataPointForDoughnutSeries(chartData.getCell(0, 2, 1, 10));
series.getDataPoints().addDataPointForDoughnutSeries(chartData.getCell(0, 3, 1, 1));
ptChart.getChartData().getCategories().add(chartData.getCell(0, 1, 0, "Apple"));
ptChart.getChartData().getCategories().add(chartData.getCell(0, 2, 0, "Pineapple"));
ptChart.getChartData().getCategories().add(chartData.getCell(0, 3, 0, "Pineapplepen"));
}
}
}
pt.save("doughnut-chart-test-result.pptx", SaveFormat.Pptx);
}
Here are the input and the output file:
doughnut-chart-test.zip (70.7 KB)
The resulting chart has lost every style settings, as colors, labels and so on.
I know that I can code the style in the following way:
ptChart.getChartData().getSeriesGroups().get_Item(0).setDoughnutHoleSize((byte) 60);
ptChart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(false);
ptChart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowPercentage(true);
ptChart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowCategoryName(true);
ptChart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowLeaderLines(true);
ptChart.getChartData().getSeries().get_Item(0).getParentSeriesGroup().setColorVaried(true);
but I could have different charts with different styles in my presentation, so is there a way to keep the original style settings without writing them in the code?