Doughnut Chart Data Labels Are Missing when Label Color Is Changed in Java

I need to set the donut chart label to white color. My code below will work for default color for the chart label, but when I try to set the color to white, the label is not displaying. The same works for the Pie chart label.

Code for Donut chart:

import java.awt.Color;

import com.aspose.slides.ChartType;
import com.aspose.slides.FillType;
import com.aspose.slides.IChart;
import com.aspose.slides.IChartDataWorkbook;
import com.aspose.slides.IChartSeries;
import com.aspose.slides.NullableBool;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;

public class DonutChartTest {

  public static void main(String[] args) {
    // Create an instance of Presentation class
    Presentation pres = new Presentation();
    try {
      // Add chart with default data
      IChart chart =
          pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Doughnut, 100, 100, 400, 400);

      // Setting chart Title
      chart.getChartTitle().addTextFrameForOverriding("Sample Title");
      chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat()
          .setCenterText(NullableBool.True);
      chart.getChartTitle().setHeight(20);
      chart.setTitle(true);

      // Setting the index of chart data sheet
      int defaultWorksheetIndex = 0;

      // Getting the chart data worksheet
      IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

      // Delete default generated series and categories
      chart.getChartData().getSeries().clear();
      chart.getChartData().getCategories().clear();

      // Adding new categories
      chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "First Qtr"));
      chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "2nd Qtr"));
      chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "3rd Qtr"));

      // Adding new series
      IChartSeries series =
          chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), chart.getType());
      
      //add by me: 
      series.getLabels().getDefaultDataLabelFormat().setShowPercentage(true);
      
      // Now populating series data
      series.getDataPoints()
          .addDataPointForDoughnutSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
      series.getDataPoints()
          .addDataPointForDoughnutSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
      series.getDataPoints()
          .addDataPointForDoughnutSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));

      chart.getChartData().getSeriesGroups().get_Item(0).setDoughnutHoleSize((byte) 40);

      // series.getDataPoints()
      // .addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
      // series.getDataPoints()
      // .addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
      // series.getDataPoints()
      // .addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));

      // set the label text color 
      // comment out the the following lines, the label is displayed in the donut chart
      series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat()
          .getFillFormat().setFillType(FillType.Solid);
      series.getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat()
          .getFillFormat().getSolidFillColor().setColor(Color.WHITE);

      series.getParentSeriesGroup().setColorVaried(true);
      pres.save("donutWhiteColorPercent.pptx", SaveFormat.Pptx);
    } finally {
      if (pres != null)
        pres.dispose();
    }
  }
}

donutChartLabel.7z (57.9 KB)

Please show me an example code how to apply the color change for the label.
Appreciate your help!

@liqingruan
Thank you for contacting support.
We will investigate your question and come back with the results.

@liqingruan,
I’ve reproduced the problem with changing color of the chart data labels and added a ticket with ID SLIDESJAVA-38928 to our issue tracking system. We apologize for any inconvenience. Our development team will investigate the case. You will be notified when a new release of Aspose.Slides with a fix is published.

It would be great if you could share the following additional information:

  • OS version on which the code was executed
  • JDK version in your app

We will then also test a solution in an environment similar to yours.

Windows 10
Java 8

@liqingruan,
Thank you for the additional information. I’ve forwarded it to our developers.

@Andrey_Potapov
Appreciate your help!