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.
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.
@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;
}
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”.
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.