Back to Devexpress

Axis.NumberFormat Property

officefileapi-devexpress-dot-spreadsheet-dot-charts-dot-axis-46cf47ec.md

latest3.8 KB
Original Source

Axis.NumberFormat Property

Provides access to number format options for numerical values displayed in axis labels.

Namespace : DevExpress.Spreadsheet.Charts

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
NumberFormatOptions NumberFormat { get; }
vb
ReadOnly Property NumberFormat As NumberFormatOptions

Property Value

TypeDescription
NumberFormatOptions

A NumberFormatOptions object that contains formatting options for displaying numbers.

|

Remarks

You can specify how to display numeric values on the axis by applying number formats. For example, a number in the axis label can appear as a percentage, decimal, currency, accounting, date or time value. To apply a number format to axis 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 following example demonstrates how to create a clustered column chart and display numbers on the value axis 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.

View Example

csharp
Worksheet worksheet = workbook.Worksheets["chartTask3"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B3:C5"]);
chart.TopLeftCell = worksheet.Cells["H2"];
chart.BottomRightCell = worksheet.Cells["N14"];

// Format the axis labels.
Axis axis = chart.PrimaryAxes[1];
axis.NumberFormat.FormatCode = "0%";
axis.NumberFormat.IsSourceLinked = false;

// Hide the legend.
chart.Legend.Visible = false;
vb
Dim worksheet As Worksheet = workbook.Worksheets("chartTask3")
workbook.Worksheets.ActiveWorksheet = worksheet

' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B3:C5"))
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")

' Format the axis labels.
Dim axis As Axis = chart.PrimaryAxes(1)
axis.NumberFormat.FormatCode = "0%"
axis.NumberFormat.IsSourceLinked = False

' Hide the legend.
chart.Legend.Visible = False

See Also

FormatCode

IsSourceLinked

Axis Interface

Axis Members

DevExpress.Spreadsheet.Charts Namespace