DataLabelBase.NumberFormat Property
Provides access to number format options for numerical values displayed in data labels.
Namespace: DevExpress.Spreadsheet.Charts
Assembly: DevExpress.Spreadsheet.v24.1.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Property Value
Type | Description |
---|---|
NumberFormatOptions | A NumberFormatOptions object that contains formatting options for displaying numbers. |
Remarks
You can specify how to display numeric values in data labels by applying number formats. For example, a number in the data label can appear as a percentage, decimal, currency, accounting, date or time value. To apply a number format to data labels, assign the corresponding number format code to the NumberFormatOptions.FormatCode property. This property takes effect only when the NumberFormatOptions.IsSourceLinked property, which allows you to keep the number format linked to the worksheet cell, is set to false.
Example
The example below demonstrates how to create a clustered column chart and format numeric values displayed in data labels as percentage values. To apply the number format, set the NumberFormatOptions.IsSourceLinked property to false and assign the corresponding format code to the NumberFormatOptions.FormatCode property.
Worksheet worksheet = workbook.Worksheets["chartTask3"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:D4"]);
chart.TopLeftCell = worksheet.Cells["H2"];
chart.BottomRightCell = worksheet.Cells["N14"];
// Display data labels and specify their position within the chart.
chart.Views[0].DataLabels.ShowValue = true;
chart.Views[0].DataLabels.LabelPosition = DataLabelPosition.Center;
// Format data labels.
chart.Views[0].DataLabels.NumberFormat.FormatCode = "0%";
chart.Views[0].DataLabels.NumberFormat.IsSourceLinked = false;