Setting Custom Labels for Data Series

I’m trying to set a custom label for a series of data so that the chart legend displays that custom label.

What I have below only creates a new series but then I’m unable to add any data points to it.

My request is this: How do I change the data series label?

ISlide slide = pres.Slides[slideNum];
IChart chart = slide.Shapes.AddChart(ChartType.ClusteredColumn, 100, 100, 500, 400);

chart.ChartData.Series.Add(Convert.ToString(dataTable.Columns[1]), ChartType.ClusteredColumn);
chart.ChartData.Series[0].DataPoints[0].Value.Data = dataTable.Rows[0][1];
chart.ChartData.Series[0].DataPoints[1].Value.Data = dataTable.Rows[1][1];
chart.ChartData.Series[0].DataPoints[2].Value.Data = dataTable.Rows[2][1];
chart.ChartData.Series[0].DataPoints[3].Value.Data = dataTable.Rows[3][1];

Hi Caleb,

Thank you for posting.

I have observed your comments and like to request you to please visit this documentation link for your kind reference.

I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,

Hi Muhammad,

Unfortunately this was not too helpful. Can you please give me a code snippet of how to change a specific data series label?

Hi Caleb,

I have observed your comments and like to request you to please try using below sample code on your end to serve the purpose on your end.

//Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();

//Access first slide
ISlide sld = pres.Slides[0];

// Add chart with default data
IChart chart = sld.Shapes.AddChart(ChartType.Doughnut, 0, 0, 500, 500);
IChartSeries series = chart.ChartData.Series[0];

//first label will be show series name
IDataLabel lbl = series.DataPoints[0].Label;
lbl.AddTextFrameForOverriding("");
lbl.TextFrameForOverriding.Paragraphs[0].Portions[0].Text = "Sample Text";
lbl.TextFrameForOverriding.Paragraphs[0].Portions[0].PortionFormat.FontHeight = 18;
lbl.TextFrameForOverriding.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillType.Solid;
lbl.TextFrameForOverriding.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Red;

//Save presentation with chart
pres.Save(@"D:/DataLabel_16.3.0.pptx", Aspose.Slides.Export.SaveFormat.Pptx);

I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,