Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DataLabelCollection.SetReference(CellRange) Method

Specifies the cell range used as a source for the data labels.

Namespace: DevExpress.Spreadsheet.Charts

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

NuGet Package: DevExpress.Spreadsheet.Core

#Declaration

void SetReference(
    CellRange range
)

#Parameters

Name Type Description
range CellRange

A cell range used as a reference to data labels.

#Exceptions

Type Description
InvalidOperationException

Thrown if the passed range is a 2D range (contains more than one row and/or column).

ArgumentException

Thrown if the passed range is a union (complex) range.

#Remarks

Set the Series.UseCustomDataLabels property to true to specify cell values as data labels.

#Example

The code sample below shows how to use cell values as data labels:

Chart with data labels from cell values

using DevExpress.Spreadsheet;
using DevExpress.Spreadsheet.Charts;

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

// Create a chart and specify its location
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L15"];
// Specify the chart style
chart.Style = ChartStyle.ColorGradient;

chart.Series[0].UseCustomDataLabels = true;
var customDataLabels = chart.Series[0].CustomDataLabels;
customDataLabels.SetReference(worksheet["D3:D8"]);
See Also