Hello, I am trying to use Aspose Slides for Java to generate a chart that shows percents. Here is a screenshot of the resulting chart and data in Powerpoint:
Screenshot_20181015_110812.png (196.4 KB)
Here is the code I am using to generate it from a template slide:
`
Chart chart = findSlideChart(questionSlide);
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
workbook.clear(0);
workbook.getCell(0, 0, 0, “”);
int col = 1;
for (String cc : question.columnChoices) {
workbook.getCell(0, 0, col, cc);
col++;
}
row = 1;
int totalResponses = question.responses.size();
for (String rc : question.rowChoices) {
workbook.getCell(0, row, 0, rc);
// get percents for this answer in each rank
col = 1;
for (String cc : question.columnChoices) {
long num = question.responses.stream().filter( r -> r.jsonData.get(rc).equals(cc)).count();
float percent = (float) num / (float) totalResponses;
long val = Math.round(percent * 100);
workbook.getCell(0, row, col, percent);
col++;
}
row++;
}
range = "Sheet1!A1:" + getChar(question.columnChoices.size()) + "" + (question.rowChoices.size() + 1);
chart.getChartData().setRange(range);
IChartSeriesCollection seriesCollection = chart.getChartData().getSeries();
for (IChartSeries series : seriesCollection) {
series.getParentSeriesGroup().setOverlap((byte) 100);
final IDataLabelFormat labelFormat = series.getLabels().getDefaultDataLabelFormat();
labelFormat.setShowValue(true);
for (IDataLabel label : series.getLabels()) {
label.getDataLabelFormat().setNumberFormat("0.0%");
}
}
`
I have tried several variations of this and I cannot get the data labels to display as “50.0%”, they always show 0.5. Similarly, I would like the data label font to be white in color instead of black, but I cannot find a way to make that happen either. Can someone assist with this? Thanks!