Axes refers to the lines on a chart that help you understand the scales and dimensions of the data being displayed.
There are three types of axes in charts:
You can use the properties of the IAxis Interface to configure an axis in a chart and to customize other elements, such as Axis title, Format, Display Unit, Logarithmic Scale, Number Format, Cross, and many more.
By default, a chart contains two primary axes - Primary Category Axis (X-axis) and Primary Value Axis (Y-axis). However, if a single set of primary axes is not sufficient to illustrate the data, such as when you are working with mixed data types, like combining a bar chart with a line chart, then secondary axes can be used. Secondary axes help you to efficiently represent datasets with different scales or units on the same chart.
Use the ShowAxis method of the IChart interface to show the axis. This method displays the axis specified by AxisType and AxisGroup enumerations.
Note: There are some charts, like pie charts, sunburst charts, or treemaps, do not use axes. Instead, they represent data visually through proportions or hierarchies.
The following example code demonstrates how to configure primary and secondary axes for better data representation.
Let's discuss some of the common axis elements used to configure chart in the following sections.
Axis titles are the short text descriptions that explain the data displayed along a particular axis. They typically appear along the horizontal and vertical axes of a chart.
To display an axis title, you need to set the HasTitle property of the IAxis interface to true. After that, you can set the text of the axis title using the Text property from the IAxisTitle interface. Additionally, Spread for WPF also allows you to customize axis titles using various other properties of the IAxisTitle interface, such as Alignment, Orientation, TextOrientation, and so on.
Refer to the following example code to set the title for axes.
When configuring the chart axis in your worksheet, you can set the display unit for a specific axis and customize its label style using the properties of the IAxis interface, such as DisplayUnit, DisplayUnitCustom, and DisplayUnitLabel. If the label defined by the DisplayUnit or DisplayUnitCustom property is not shown on the specified axis, you can ensure it appears by setting the HasDisplayUnitLabel property to true. By default, this property value is true.
Refer to the following example code to set display unit for the value axis and configure its label.
While configuring the axis of a chart, you can set the position and layout of the tick-mark labels as per your choice using the various properties of the IAxis interface, such as TickLabelPosition, TickLabels, TickLabelSpacing, TickLabelSpacingIsAuto, and TickMarkSpacing.
Refer to the following example code to configure the tick mark label's position and layout.
Gridlines refer to the horizontal and vertical lines appearing in the plot area of a chart. Only axes in the primary axis group can have gridlines.
In charts, the major gridline and minor gridline have the same axis type. While configuring the axis of a chart, you can also set the display styles of major and minor gridlines as per your choice. Set the HasMajorGridlines and the HasMinorGridlines properties of the IAxis interface to true to display the major and minor gridlines. And then, using the properties of MajorGridlines and MinorGridlines, you can customize the desired gridline styles.
Refer to the following example code to set minor gridlines' color.