Following Chart documentation do not bring the right result

I am trying to follow the documentation on this link to insert a pie chart on my document.
But I think think it’s not updated.
It says that we should add the following lines to show some labels on the Chart.Pie

ChartDataLabelCollection labels = series.DataLabels;
labels.ShowPercentage = true;
labels.ShowValue = true;
labels.ShowLeaderLines = false;
labels.Separator = " - ";

The vscode instantaneously gives me the red underline as follows:
image.png (28.8 KB)

It clearly seems that labels are an IEnumerable, so I’ve tried the following approach:

  ChartDataLabelCollection labels = series.DataLabels;
  labels.Select(x => x.ShowPercentage = true);
  labels.Select(x => x.ShowValue = true);
  labels.Select(x => x.ShowLeaderLines = false);
  labels.Select(x => x.Separator = " - ");

It compiles, but it doesn’t show any label at all.
image.png (9.5 KB)

The expected result would be:
image.png (9.3 KB)

In my humble opinion, what is missing is that Label Position option, because, as soon as I open the output word document, select the chart and click on Add Chart Element > DataLabels > and choose one of the options, the labels show up.

@jonroosevelt

We have tested the scenario and have not found the shared issue. Could you please create simple Visual Studio project, ZIP and attach it here for testing? Please also share the .NET framework/Core version that you are using. We will investigate the issue and provide you more information on it.

Even doing it with a simple project, stills not working properly.
I’ve opened it in several machines to make sure it wasn’t a problem with my MS Word.
image.png (11.8 KB)
piechart.zip (54.9 KB)
In my real project, I’m using dotnet core 2.0, but in this project I’ve sent you I’m using “2.1.808” as you can find it in the global.json

@jonroosevelt

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-21315 . You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

1 Like

No inconvenience at all.
Thank you so much Tahir.

@jonroosevelt

Please use series.HasDataLabels = true; as shown below to get the desired output. We have closed this issue as ‘Not a bug’.

ChartDataLabelCollection labels = series.DataLabels;
labels.ShowPercentage = true;
labels.ShowValue = true;
labels.ShowLeaderLines = true;
labels.Separator = " - ";
series.HasDataLabels = true;