Cannot set data labels to display as percents

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!

@glicker,

I have observed your requirements and suggest you to please visit this documentation link for your convenience. I hope the shared information will be helpful.

I have read that documentation link several times. but it is in fact just a description and not a code example. I am not clear on how to translate that description into code. Can you assist with this?

@glicker,

Can you please try accessing the documentation link again.

@mudassir.fayyaz Thank you, I now see the code that goes with the description, and I was able to change the number format of the cells! Here is what the chart looks like now:

Screenshot_20181015_131559.png (64.8 KB)

I have 2 additional questions:

  1. How to remove the 0.0% labels that are at the left and right end of each bar?
  2. How to change the color of the labels on top of the bars to be white instead of black?

Thank you again!

@mudassir.fayyaz Disregard last 2 questions, I figured this out. Thank you!

@glicker,

I have observed the image shared by you and request you to please provide a working sample code to reproduce the issue on our end to help you further to address your following question.