Back to Devexpress

NumberFormatOptions.FormatCode Property

officefileapi-devexpress-dot-spreadsheet-dot-charts-dot-numberformatoptions.md

latest7.8 KB
Original Source

NumberFormatOptions.FormatCode Property

Specifies a number format (in the invariant culture) used to display numeric values in chart elements.

Namespace : DevExpress.Spreadsheet.Charts

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
string FormatCode { get; set; }
vb
Property FormatCode As String

Property Value

TypeDescription
String

The number format to apply to chart elements.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to FormatCode
Axis

.NumberFormat .FormatCode

| | DataLabelBase |

.NumberFormat .FormatCode

| | TrendlineLabel |

.NumberFormat .FormatCode

|

Remarks

The Spreadsheet allows you to use Microsoft Excel number formats to display numeric values on a chart as currency, percentages, decimals, and so on.

Use the FormatCode option to specify a number format in the invariant culture. Disable the NumberFormatOptions.IsSourceLinked property to indicate that the applied format differs from the number format of the source cells.

You can also use the FormatCodeLocal property to obtain or specify a number format based on the current (local) culture defined by the DocumentOptions.Culture property.

Example

The following example demonstrates how to create a clustered column chart and display numbers on the value axis as percentage values. To apply a number format, set the NumberFormatOptions.IsSourceLinked property to false and assign the required 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"];

// Apply a number format to 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")

' Apply a number format to axis labels.
Dim axis As Axis = chart.PrimaryAxes(1)
axis.NumberFormat.FormatCode = "0%"
axis.NumberFormat.IsSourceLinked = False

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

The following code snippets (auto-collected from DevExpress Examples) contain references to the FormatCode 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.

wpf-spreadsheet-chart-api/CS/SpreadsheetWPFChartAPISamples/CodeExamples/DataLabelsActions.cs#L59

csharp
// Format data labels.
chart.Views[0].DataLabels.NumberFormat.FormatCode = "0%";
chart.Views[0].DataLabels.NumberFormat.IsSourceLinked = false;

winforms-spreadsheet-chart-api/CS/SpreadsheetChartAPISamples/CodeExamples/DataLabelsActions.cs#L59

csharp
// Format data labels.
chart.Views[0].DataLabels.NumberFormat.FormatCode = "0%";
chart.Views[0].DataLabels.NumberFormat.IsSourceLinked = false;

spreadsheet-document-api-chart-examples/CS/SpreadsheetDocServerChartAPISamples/CodeExamples/DataLabelsActions.cs#L67

csharp
// Format data labels.
chart.Views[0].DataLabels.NumberFormat.FormatCode = "0%";
chart.Views[0].DataLabels.NumberFormat.IsSourceLinked = false;

wpf-spreadsheet-chart-api/VB/SpreadsheetWPFChartAPISamples/CodeExamples/DataLabelsActions.vb#L63

vb
' Format data labels.
chart.Views(0).DataLabels.NumberFormat.FormatCode = "0%"
chart.Views(0).DataLabels.NumberFormat.IsSourceLinked = False

winforms-spreadsheet-chart-api/VB/SpreadsheetChartAPISamples/CodeExamples/DataLabelsActions.vb#L62

vb
' Format data labels.
chart.Views(0).DataLabels.NumberFormat.FormatCode = "0%"
chart.Views(0).DataLabels.NumberFormat.IsSourceLinked = False

spreadsheet-document-api-chart-examples/VB/SpreadsheetDocServerChartAPISamples/CodeExamples/DataLabelsActions.vb#L70

vb
' Format data labels.
chart.Views(0).DataLabels.NumberFormat.FormatCode = "0%"
chart.Views(0).DataLabels.NumberFormat.IsSourceLinked = False

See Also

FormatCodeLocal

IsSourceLinked

NumberFormatOptions Interface

NumberFormatOptions Members

DevExpress.Spreadsheet.Charts Namespace