Free Support Forum - aspose.com

Unable to hide/delete Doughnut chart legend entries with 1 series

Hiding legend entries does not work in my case using a doughnut chart with 1 series and 2 data points.
I’m using aspose slides 19.9.0 but could reproduce with 20.9.0.
I only want to hide the second data point in reality, but neither points can be hidden as can be seen in the code.

        Presentation pres = new Presentation();

        ISlide slide = pres.Slides[0];

        //Creating the default chart
        IChart chart = slide.Shapes.AddChart(ChartType.Doughnut, 0, 0, 400, 400);

        //Getting the default chart data worksheet index
        int wsIndex = 0;

        chart.ChartData.ChartDataWorkbook.Clear(wsIndex);
        chart.ChartData.Series.Clear();
        chart.ChartData.Categories.Clear();

        //Getting the chart data worksheet
        IChartDataWorkbook fact = chart.ChartData.ChartDataWorkbook;

        //Add new series
        chart.ChartData.Series.Add(fact.GetCell(wsIndex, 0, 1, "Series 1"), chart.Type);

        chart.ChartData.SeriesGroups[0].DoughnutHoleSize = 75;

        chart.ChartData.Categories.Add(fact.GetCell(wsIndex, 1, 0, "Cat"));
        chart.ChartData.Categories.Add(fact.GetCell(wsIndex, 2, 0, "Dog"));

        var point = chart.ChartData.Series[0].DataPoints.AddDataPointForDoughnutSeries(fact.GetCell(wsIndex, 1, 1, 25));

        point.Format.Fill.FillType = FillType.Solid;
        point.Format.Fill.SolidFillColor.Color = Color.DeepSkyBlue;

        // does not work
        point.RelatedLegendEntry.Hide = true;

        point = chart.ChartData.Series[0].DataPoints.AddDataPointForDoughnutSeries(fact.GetCell(wsIndex, 2, 1, 75));

        point.Format.Fill.FillType = FillType.Solid;
        point.Format.Fill.SolidFillColor.Color = Color.LightGray;

        // does not work
        point.RelatedLegendEntry.Hide = true;

        // does not work
        chart.Legend.Entries[0].Hide = true;
        // does not work
        chart.Legend.Entries[1].Hide = true;

        pres.Save("AsposeChart.pptx", SaveFormat.Pptx);

@maggre

Can you please share the generated file along with presentation with desired output so that I may compare and help you further.