Skip to main content

ChartView.DataLabels Property

Provides access to options used to modify all data labels within a chart view.

Namespace: DevExpress.Spreadsheet.Charts

Assembly: DevExpress.Spreadsheet.v24.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

DataLabelOptions DataLabels { get; }

Property Value

Type Description
DataLabelOptions

A DataLabelOptions object containing options for displaying and formatting data labels.

Remarks

Use the DataLabels property to access the DataLabelOptions object, which inherits data label options from the DataLabelBase interface. Use the object’s properties to display data labels on a chart and specify what information should appear in each label: the data point value (DataLabelBase.ShowValue), the series name (DataLabelBase.ShowSeriesName), the category name (DataLabelBase.ShowCategoryName), the bubble size (DataLabelBase.ShowBubbleSize), the percentage value (DataLabelBase.ShowPercent), or the legend key (DataLabelBase.ShowLegendKey). When the data label contains multiple items, use the DataLabelBase.Separator property to specify a character to separate these items. To position data labels on a chart, utilize the DataLabelBase.LabelPosition property. To apply a number format to data labels, use the DataLabelBase.NumberFormat property.

To adjust the data labels of a particular series, use the Series.CustomDataLabels property.

Example

The example below demonstrates how to create a pie chart and adjust the display settings of its data labels. In particular, set the DataLabelBase.ShowCategoryName and DataLabelBase.ShowPercent properties to true to display the category name and percentage value in a data label at the same time. To separate these items, assign a new line character to the DataLabelBase.Separator property, so the percentage value will be automatically wrapped to a new line.

View Example

Worksheet worksheet = workbook.Worksheets["chartTask1"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.Pie, worksheet["B2:C7"]);
chart.TopLeftCell = worksheet.Cells["E2"];
chart.BottomRightCell = worksheet.Cells["K15"];

// Display the category name and percentage.
DataLabelOptions dataLabels = chart.Views[0].DataLabels;
dataLabels.ShowCategoryName = true;
dataLabels.ShowPercent = true;
dataLabels.Separator = "\n";

// Set the chart style.
chart.Style = ChartStyle.ColorGradient;
// Hide the legend.
chart.Legend.Visible = false;
// Set the angle of the first pie-chart slice.
chart.Views[0].FirstSliceAngle = 100;

The following code snippets (auto-collected from DevExpress Examples) contain references to the DataLabels property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also