Skip to main content

CustomAxisLabelCollection Class

Represents a collection that stores the custom labels of a particular axis.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v24.1.dll

NuGet Package: DevExpress.Charts

Declaration

public sealed class CustomAxisLabelCollection :
    ChartElementNamedCollection,
    IEnumerable<ICustomAxisLabel>,
    IEnumerable

The following members return CustomAxisLabelCollection objects:

Remarks

Each axis (in particular, an axis of the AxisX or AxisY type) can hold a collection of custom labels which can be accessed via the Axis2D.CustomLabels property and is represented by the CustomAxisLabelCollection class. The properties and methods exposed by the CustomAxisLabelCollection class can be used to perform common collection operations such as adding new or deleting existing items. Each item of the collection is represented by a CustomAxisLabel object. Individual custom labels can be accessed either using indexer notation or by their names using the specific methods of the collection.

Note that if this collection contains any custom label, the default labels are not displayed within the corresponding 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
    }
}
See Also