How to Read Text of Chart Data Label using Aspose.Slides?

Hello

I need to read the data label texts from a chart for which the data-label values are not linked to a cell (DataLabelFormat.ShowLabelValueFromCell = false). How can I read the content of the data labels?

label.TextFrameForOverriding.Text is empty, and .GetActualLabelText() throws an exception.

Any help would be much appreciated!

Thanks
Fred Balkenende

@officereports,
Welcome to our community! Thank you for posting the query.

Could you please share a presentation sample with the chart and point out the data labels?

Thanks Andrey!

In the attached presentation I can see the values for the data points, bu I cannot find out where to read the data labels so I can see the texts like ‘5*’, ‘7*’, ‘15*’ etc…

On the first slide the DataSourceType is DoubleLiterals, on the second slide it is Workbook. On neither slide I can read the correct labels.

Could it be a bug?

Thanks
Fred

ReadChartDataLabels.7z (48.7 KB)

@officereports,
Thank you for the presentation file. It will take me a while to figure this out. We will reply to you as soon as possible.

@officereports,
Unfortunately, I have not found how to do that. I logged the issue with ID SLIDESNET-42880 in our tracking system. Our development team will investigate this case. We will inform you of any progress.

@officereports,
Our development team investigated the issue. The following code example helps you to read the values from data points of the charts:

private static List<List<string>> GetLabels(IChart chart)
{
    var result = new List<List<string>>();
    int j = 0;

    foreach (var column in chart.ChartData.Series)
    {
        for (var i = 0; i < column.DataPoints.Count; i++)
        {
            var point = column.DataPoints[i];

            if (point.Value.Data != null && double.TryParse(point.Value.Data.ToString(), out double value) && value != 0)
            {
                if (result.Count <= j)
                {
                    result.Add(new List<string>());
                }

                result[j].Add((Math.Round((double)point.Value.Data)) + "*");
                j++;
            }
        }

        j = 0;
    }

    return result;
}

Documents: Chart Data Label
API Reference: IChartDataPoint Interface

Hi Andrey

Your code just adds a ‘*’ to the labels that do not have value zero. That is really not what I’m looking for. Other charts will look different, with sometimes other characters behind numbers and sometimes just numbers.

I think this is a bug in Aspose.Slides. When a specific chart point has a label containing “2.3 ABC”, then the point.Label property should have value “2.3 ABC”.

Are you planning on fixing this bug?

Where can I access the bug report “SLIDESNET-42880”? It is NOT resolved yet in my opinion.

Thanks
Fred

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

You can see the issue status at the bottom of this forum thread.

The issues you have found earlier (filed as SLIDESNET-42880) have been fixed in Aspose.Slides for .NET 22.2 (ZIP, MSI).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.