Back to Devexpress

CustomAxisLabelCollection Class

corelibraries-devexpress-dot-xtracharts-4cf8e658.md

latest5.8 KB
Original Source

CustomAxisLabelCollection Class

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

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
public sealed class CustomAxisLabelCollection :
    ChartElementNamedCollection,
    IEnumerable<ICustomAxisLabel>,
    IEnumerable
vb
Public NotInheritable Class CustomAxisLabelCollection
    Inherits ChartElementNamedCollection
    Implements IEnumerable(Of 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.

csharp
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
    }
}
vb
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraCharts

Namespace CustomAxisLabels
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

        #Region "#CustomLabels"
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
            ' Cast the chart's diagram to the XYDiagram type, to access its axes.
            Dim diagram As XYDiagram = TryCast(chartControl.Diagram, XYDiagram)
            If diagram Is Nothing Then
                Return
            End If

            Dim axisX As AxisX = diagram.AxisX
            ' Add a custom label to the X-axis.
            axisX.CustomLabels.Add(New CustomAxisLabel(name:= "State of Michigan", value:= "Michigan") With { _
                .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
        End Sub
        #End Region
    End Class
End Namespace

Inheritance

Object CollectionBase ChartCollectionBase ChartElementNamedCollection CustomAxisLabelCollection

See Also

CustomAxisLabelCollection Members

CustomLabels

CustomAxisLabel

Axis Labels

DevExpress.XtraCharts Namespace