Back to Devexpress

Axis.DisplayUnits Property

officefileapi-devexpress-dot-spreadsheet-dot-charts-dot-axis-331b0a0c.md

latest5.2 KB
Original Source

Axis.DisplayUnits Property

Provides access to options used to specify the display units for the value axis.

Namespace : DevExpress.Spreadsheet.Charts

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
DisplayUnitOptions DisplayUnits { get; }
vb
ReadOnly Property DisplayUnits As DisplayUnitOptions

Property Value

TypeDescription
DisplayUnitOptions

A DisplayUnitOptions object.

|

Remarks

Use the DisplayUnits property to access the DisplayUnitOptions object that allows you to specify display units for the value axis. Display units are useful for charting large numbers. For example, if the value axis stretches from 10,000 to 100,000, you can use the DisplayUnitOptions.UnitType property to shorten the text of axis labels and display numbers along the axis as 10 to 100. You can also specify the custom scaling value for the display units by utilizing the DisplayUnitOptions.CustomUnit property. To show a label that describes what the specified units express, use the DisplayUnitOptions.ShowLabel and DisplayUnitOptions.Label properties.

The image below shows the chart with the value axis scale set to Thousands (the chart is displayed in Microsoft® Excel®).

Note

If you try to specify the display units for the category or series axis, an exception occurs.

Example

The example below demonstrates how to create a clustered column chart and specify the display units for the value axis by utilizing the Axis.DisplayUnits property. This property provides access to the DisplayUnitOptions object containing display unit settings. Set the DisplayUnitOptions.UnitType property to DisplayUnitType.Thousands to divide values on the axis by 1,000. To show the display unit label, set the DisplayUnitOptions.ShowLabel property to true.

View Example

csharp
Worksheet worksheet = workbook.Worksheets["chartTask7"];
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["N17"];

// Change the scale of the value axis.
AxisCollection axisCollection = chart.PrimaryAxes;
Axis valueAxis = axisCollection[1];
valueAxis.Scaling.AutoMax = false;
valueAxis.Scaling.Max = 8000000;
valueAxis.Scaling.AutoMin = false;
valueAxis.Scaling.Min = 0;

// Specify display units for the value axis.
valueAxis.DisplayUnits.UnitType = DisplayUnitType.Thousands;
valueAxis.DisplayUnits.ShowLabel = true;

// Set the chart style.
chart.Style = ChartStyle.ColorBevel;
chart.Views[0].VaryColors = true;

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

' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B2:C8"))
chart.TopLeftCell = worksheet.Cells("F2")
chart.BottomRightCell = worksheet.Cells("N17")

' Change the scale of the value axis.
Dim axisCollection As AxisCollection = chart.PrimaryAxes
Dim valueAxis As Axis = axisCollection(1)
valueAxis.Scaling.AutoMax = False
valueAxis.Scaling.Max = 8000000
valueAxis.Scaling.AutoMin = False
valueAxis.Scaling.Min = 0

' Specify display units for the value axis.
valueAxis.DisplayUnits.UnitType = DisplayUnitType.Thousands
valueAxis.DisplayUnits.ShowLabel = True

' Set the chart style.
chart.Style = ChartStyle.ColorBevel
chart.Views(0).VaryColors = True

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

See Also

Axis Interface

Axis Members

DevExpress.Spreadsheet.Charts Namespace