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

CustomAxisLabel Class

Represents an individual custom label of an axis.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v21.2.dll

NuGet Package: DevExpress.Charts

Declaration

public sealed class CustomAxisLabel :
    ChartElementNamed,
    ICustomAxisLabel,
    IAxisValueContainer,
    IScrollBarAnnotation

Remarks

The CustomAxisLabel class contains the settings that define the functionality of a custom label within an axis.

In addition to the settings inherited from the base ChartElementNamed class, the CustomAxisLabel class implements properties that allow you to specify the corresponding axis value which the label is displayed at (CustomAxisLabel.AxisValue) and control the label’s visibility (CustomAxisLabel.Visible).

Custom label objects associated with a particular axis are contained within the axis’s Axis2D.CustomLabels collection which is represented by an object of the CustomAxisLabelCollection type. A particular CustomAxisLabel object can be accessed within the collection either using indexer notation (see the CustomAxisLabelCollection.Item property) or by its name using specific methods of the collection (see the CustomAxisLabelCollection.GetAxisLabelByName method).

Custom labels defined for an axis can’t be displayed together with its default labels. If an axis’s Axis2D.CustomLabels collection contains any custom label whose visibility is set to true, the default labels are not displayed within the axis. Note that most of the appearance settings of an axis’s custom labels are defined via the Axis2D.Label property of the axis.

For more information, refer to Axis Labels.

Example

This example demonstrates how custom axis labels can be created and customized at runtime.

using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;

namespace CustomAxisLabels {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        #region #CustomLabels
        private void Form1_Load(object sender, EventArgs e) {
            // Cast the chart's diagram to the XYDiagram type, to access its axes.
            XYDiagram diagram = chartControl.Diagram as XYDiagram;
            if(diagram == null) return;

            AxisX axisX = diagram.AxisX;
            // Add a custom label to the X-axis.
            axisX.CustomLabels.Add(new CustomAxisLabel(name: "State of Michigan", value: "Michigan") {
                TextColor = Color.FromArgb(255, 74, 74, 74),
                BackColor = Color.FromArgb(255, 225, 225, 225)
            });
            // Make auto-generated and custom labels visible at the same time.
            axisX.LabelVisibilityMode = AxisLabelVisibilityMode.AutoGeneratedAndCustom;
        }
        #endregion
    }
}

Inheritance

See Also