Free Support Forum - aspose.com

Error in modifying data label position of Doughnut Chart

Hi Team:
I upgraded Dll from 21.3 to 21.5 and found that I couldn’t modify the data label position of the doughtnut Chart normally.
Sample code:
Workbook workbook = new Workbook(“e:\doughtnut.xlsx”);
Worksheet worksheet = workbook.Worksheets[0];

        int chartIndex = worksheet.Charts.Add(ChartType.Pie, 0, 5, 20, 15);
        Chart chart = worksheet.Charts[chartIndex];
        chart.Title.IsDeleted = true;
        chart.PlotArea.Area.FillFormat.FillType = FillType.None;
        chart.PlotArea.Border.FormattingType = ChartLineFormattingType.None;
        chart.ChartArea.Border.FormattingType = ChartLineFormattingType.None;
        chart.ChartArea.Area.FillFormat.FillType = FillType.None;
        chart.ShowLegend = false;
        var chartRange = $"{CellsHelper.CellIndexToName(1, 1)}:{CellsHelper.CellIndexToName(4, 1)}";
        chart.NSeries.Add(chartRange, true);
        chart.NSeries.CategoryData = $"{CellsHelper.CellIndexToName(1, 0)}:{CellsHelper.CellIndexToName(4, 0)}";
        for (int i = 1; i <= chart.NSeries.Count; i++)
        {
            var series = chart.NSeries[i - 1];
            series.Name = $"={CellsHelper.CellIndexToName(0, i)}";
            series.DataLabels.ShowCategoryName = true;
            series.DataLabels.ShowValue = true;
            series.DataLabels.SeparatorType = DataLabelsSeparatorType.Comma;
            series.DataLabels.NumberFormatLinked = true;
            series.DataLabels.Position = LabelPositionType.OutsideEnd;
        }
        chart.Calculate();
        List<(int x, int y)> points = new List<(int x, int y)>();
        foreach (var series in chart.NSeries)
        {
            foreach (ChartPoint item in series.Points)
            {
                points.Add((item.DataLabels.X, item.DataLabels.Y));
            }
        }
        chart.Type = ChartType.Doughnut;
        chart.Calculate();
        for (int i = 1; i <= chart.NSeries.Count; i++)
        {
            var series = chart.NSeries[i - 1];
            series.HasLeaderLines = false;
            var pointLength = series.Points.Count;
            for (int j = 0; j < pointLength; j++)
            {
                var pos = points[j];
                var point = series.Points[j];
                point.DataLabels.X = pos.x;
                point.DataLabels.Y = pos.y;
            }
        }
        chart.Calculate();
        workbook.Save("e:\\output.xlsx");

doughtnut.zip (77.7 KB)

@Beyond5566,

Please notice, I am able to reproduce the issue as you mentioned by using your template file. I found an issue when modifying data label position of Doughnut chart where I could not modify the data label position of the Doughnut chart properly. I also tested using v21.3 or prior versions, it works as expected. I have logged a ticket with an id “CELLSNET-48132” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.