Chart Data Labels in PowerPoint
3 Aug 202612 minutes to read
Data labels make a chart easier to understand by displaying the values of each data point. Using Presentation, you can customize the data labels in a chart without Microsoft PowerPoint.
Enable Data Labels in Chart
The following code snippet illustrates how to make the data labels visible in a chart.
// Enable the data labels in the chart.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.IsValue = true;// Enable the data labels in the chart.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.IsValue = true;' Enable the data labels in the chart.
chart.Series(0).DataPoints.DefaultDataPoint.DataLabels.IsValue = TrueCustomize the Data Labels
The following code snippet illustrates how to customize the data labels in a chart.
// Set the font size of the data labels.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
// Change the color of the data labels.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Color = OfficeKnownColors.Red;
// Make the data labels bold.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Bold = true;
// Set the font name for the data labels.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.FontName = "calibri";
// Make the data labels italic.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Italic = true;// Set the font size of the data labels.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
// Change the color of the data labels.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Color = OfficeKnownColors.Red;
// Make the data labels bold.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Bold = true;
// Set the font name for the data labels.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.FontName = "calibri";
// Make the data labels italic.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Italic = true;' Set the font size of the data labels.
chart.Series(0).DataPoints.DefaultDataPoint.DataLabels.Size = 8
' Change the color of the data labels.
chart.Series(0).DataPoints.DefaultDataPoint.DataLabels.Color = OfficeKnownColors.Red
' Make the data labels bold.
chart.Series(0).DataPoints.DefaultDataPoint.DataLabels.Bold = True
' Set the font name for the data labels.
chart.Series(0).DataPoints.DefaultDataPoint.DataLabels.FontName = "calibri"
' Make the data labels italic.
chart.Series(0).DataPoints.DefaultDataPoint.DataLabels.Italic = TrueSet the Position of Data Labels
The following code snippet illustrates how to set the position of the data labels in a chart.
// Set the position of data labels for the first series.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Center;// Set the position of data labels for the first series.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Center;' Set the position of data labels for the first series.
chart.Series(0).DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.CenterThe complete code snippet illustrating the above options is shown below.
// Open an existing PowerPoint Presentation.
using (IPresentation pptxDoc = Presentation.Open("Data/Template.pptx"))
{
// Gets the first slide.
ISlide slide = pptxDoc.Slides[0];
// Gets the chart in the slide.
IPresentationChart chart = slide.Shapes[0] as IPresentationChart;
for (int i = 0; i < chart.Series.Count; i++)
{
// Enable the data labels in the chart.
chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
// Set the font size of the data labels.
chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.Size = 10;
// Change the color of the data labels.
chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.Color = OfficeKnownColors.Black;
// Make the data labels bold.
chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.Bold = true;
// Set the position of data labels for the first series.
chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Center;
}
// Save the PowerPoint Presentation.
pptxDoc.Save("Result.pptx");
}// Open an existing PowerPoint Presentation.
using (IPresentation pptxDoc = Presentation.Open("Template.pptx"))
{
// Gets the first slide.
ISlide slide = pptxDoc.Slides[0];
// Gets the chart in the slide.
IPresentationChart chart = slide.Shapes[0] as IPresentationChart;
for (int i = 0; i < chart.Series.Count; i++)
{
// Enable the data labels in the chart.
chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
// Set the font size of the data labels.
chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.Size = 10;
// Change the color of the data labels.
chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.Color = OfficeKnownColors.Black;
// Make the data labels bold.
chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.Bold = true;
// Set the position of data labels for the first series.
chart.Series[i].DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Center;
}
// Save the PowerPoint Presentation.
pptxDoc.Save("Result.pptx");
}' Open an existing PowerPoint Presentation.
Using pptxDoc As IPresentation = Presentation.Open("Template.pptx")
' Gets the first slide.
Dim slide As ISlide = pptxDoc.Slides(0)
' Gets the chart in the slide.
Dim chart As IPresentationChart = TryCast(slide.Shapes(0), IPresentationChart)
For i As Integer = 0 To chart.Series.Count - 1
' Enable the data labels in the chart.
chart.Series(i).DataPoints.DefaultDataPoint.DataLabels.IsValue = True
' Set the font size of the data labels.
chart.Series(i).DataPoints.DefaultDataPoint.DataLabels.Size = 10
' Change the color of the data labels.
chart.Series(i).DataPoints.DefaultDataPoint.DataLabels.Color = OfficeKnownColors.Black
' Make the data labels bold.
chart.Series(i).DataPoints.DefaultDataPoint.DataLabels.Bold = True
' Set the position of data labels for the first series.
chart.Series(i).DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Center
Next
' Save the PowerPoint Presentation.
pptxDoc.Save("Result.pptx")
End UsingYou can download a complete working sample from GitHub.
Resize the Data Labels
The following code snippet illustrates how to resize the data label in chart.
// Manually resize the data label area using Layout.
chart.Series[0].DataPoints[0].DataLabels.Layout.Left = 3;
chart.Series[0].DataPoints[0].DataLabels.Layout.Top = 3;
// Manually resize the data label area using Manual Layout.
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Left = 3;
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Top = 3;// Manually resize the data label area using Layout.
chart.Series[0].DataPoints[0].DataLabels.Layout.Left = 3;
chart.Series[0].DataPoints[0].DataLabels.Layout.Top = 3;
// Manually resize the data label area using Manual Layout.
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Left = 3;
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Top = 3;' Manually resize the data label area using Layout.
chart.Series(0).DataPoints(0).DataLabels.Layout.Left = 3
chart.Series(0).DataPoints(0).DataLabels.Layout.Top = 3
' Manually resize the data label area using Manual Layout.
chart.Series(0).DataPoints(0).DataLabels.Layout.ManualLayout.Left = 3
chart.Series(0).DataPoints(0).DataLabels.Layout.ManualLayout.Top = 3Show Leader Lines
The leader lines can be shown in a chart through ShowLeaderLines API which can be set to all data labels by enabling the leader lines for DefaultDataPoint.
The following code illustrates how to enable the leader lines for all data labels in the chart.
// Enable the leader lines in Chart.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.ShowLeaderLines = true;// Enable the leader lines in Chart.
chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.ShowLeaderLines = true;' Enable the leader lines in Chart.
chart.Series(0).DataPoints.DefaultDataPoint.DataLabels.ShowLeaderLines = TrueYou can download a complete working sample from GitHub.