Skip to main content
A newer version of this page is available. .

Axis Labels

  • 6 minutes to read

This document describes how default and custom axis labels can be displayed and customized. Before you proceed with this document, you may wish to review the basics of using axes.

There are two types of axis labels available in the ASP.NET Chart Control: default and custom. And, it is possible to obtain an individual axis label item at runtime. In addition, axis labels support an algorithm which prevents label overlap during resizing.

So, this document consists of the following sections.

Default Axis Labels

The default axis labels represent textual values for major tickmarks of a diagram’s axes.

AxisLabels

Axis labels are generated automatically based on the scale type of the axis to which they belong.

Note

To organize the default axis labels in a custom order when the qualitative scale type is specified, create a static series with points corresponding to the required axis values. Then, arrange points within the series in the required order, and set this series as the first item in the chart’s collection of series.

The appearance of axis labels can be customized via the Axis2D.Label property. The AxisLabel.TextPattern property allow you to format an axis labels’ text.

Note

The appearance properties affect both default and custom axis labels, with the exception of the AxisLabel.TextPattern property, which have no effect upon custom labels.

Custom Axis Labels

Besides the default axis labels, it is possible to add custom ones.

CustomAxisLabels

An individual custom label is represented by an instance of the CustomAxisLabel class. Custom labels of an axis reside in the axis’ CustomAxisLabelCollection, which can be accessed via the Axis2D.CustomLabels property. If the collection is empty (or does not contain any visible custom labels), the chart control shows default axis labels.

To add custom labels to an axis at design time, do the following:

  1. Locate the Axis2D.CustomLabels property in the Properties window and click its ellipsis button.

    CustomLabelsCollection

  2. This invokes the Custom Axis Label Collection Editor.

    CustomAxisLabelEditor

  3. In this dialog, click Add to create a custom label, and customize its CustomAxisLabel.AxisValue and ChartElementNamed.Name properties.

    CreateCustomAxisLabel

    Note that the value set for the CustomAxisLabel.AxisValue property should lie in the range specified by the AxisBase.WholeRange property, in order for the custom label to be visible on a diagram.

    Finally, click Close, to apply the changes and quit the dialog.

Since most of the appearance settings of axis’ custom labels are defined via the Axis2D.Label property of the axis, custom axis labels share their appearance settings with an axis’ default labels.

Note

Custom labels defined for an axis cannot be displayed along with its default labels. If an axis’s Axis2D.CustomLabels collection does not contain a custom label whose CustomAxisLabel.Visible property is set to true, the default labels are displayed within the axis, instead.

Axis Label Item

There is the capability to obtain an individual axis label at runtime for both default and custom axis labels in the specific WebChartControl.CustomDrawAxisLabel event.

AxisLabelItem

For example, it may be required to customize the appearance of axis labels, based on their values. So, to achieve this, handle the event listed above, and write the required condition in its handler. The result is shown in the following image.

CustomAxisLabels_0

A code example detailing how to achieve this can be found at How to: Individually Customize Axis Labels.

Format Axis Labels

To apply a date-time format to axis labels, use the AxisLabel.TextPattern property. At design time, you can locate it in the Properties window after selecting the required axis.

This property defines a pattern for displaying text by series labels. Various placeholders enclosed in braces correspond to the available display patterns.

The full list of available placeholders is listed below.

Pattern Description
{A} Displays a series point argument.
{V} Displays series point values.
{VP} Displays series point values as percentages (for a Pie series and Full-Stacked series views).
{S} Displays the name of the series.
{G} Displays the name of a stacked group.
{W} Displays the weight (for a Bubble series).
{V1} Displays the first value (for a Range series).
{V2} Displays the second value (for a Range series).
{HV} Displays the high value (for a Financial series).
{LV} Displays the low value (for a Financial series).
{OV} Displays the open value (for a Financial series).
{CV} Displays the close value (for a Financial series).
{HINT} Displays a hint for a series point.

You can use standard and custom format specifiers, together with the placeholders to format numeric and date/time values (e.g., “{A}: {V:F1}”) .

The result is shown below.

SeriesLabels_TextPattern

To learn more, see the Format Specifiers topic.

In addition, you can specify a pattern using the Pattern Editor. The editor contains numerous predefined chart placeholders together with the date-time, numeric, percent, currency, and special formats allowing you to create a text pattern.

To invoke the editor, click the ellipsis button of the SeriesLabelBase.TextPattern property in the Properties window.

You can also customize the text pattern in the “Text Pattern” tab, which is located in the “Point Labels” Chart Wizard section.

Resolve Overlapping for Axis Labels

There are situations when axis labels do not have enough space to represent all the information, for example, of a series argument.

ResolveOverlappingAxisLabelsFalse

The resolve overlapping algorithm allows you to accomplish this task for axis labels.

Note that you do not need to write any lines of code to provide this feature, because all the necessary options (axis labels rotating, staggering and hiding) are available, by default.

ResolveOverlappingAxisLabelsEnabled

You can customize the way the resolve overlapping is provided for axis labels by using the properties of the AxisLabelResolveOverlappingOptions object. This object can be accessed via the AxisLabel.ResolveOverlappingOptions property.

AxisLabelsResolveOverlappingOptions

The following table lists properties that can be used to customize the resolve overlapping algorithm:

Member Description
AxisLabelResolveOverlappingOptions.AllowHide Gets or sets a value indicating whether or not to hide axis labels when resolving any overlap.
AxisLabelResolveOverlappingOptions.AllowRotate Gets or sets the value that indicates whether or not to rotate axis labels when resolving overlapping labels.
AxisLabelResolveOverlappingOptions.AllowStagger Gets or sets a value indicating whether or not to stagger axis labels when resolving overlapping labels.
AxisLabelResolveOverlappingOptions.MinIndent Gets or sets the minimum indent between adjacent axis labels, when an overlap resolution algorithm is applied to them.
See Also