Back to Devexpress

CustomAxisLabel Class

corelibraries-devexpress-dot-xtracharts-92a2b68f.md

latest7.0 KB
Original Source

CustomAxisLabel Class

Represents an individual custom label of an axis.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
public sealed class CustomAxisLabel :
    ChartElementNamed,
    ICustomAxisLabel,
    IAxisValueContainer,
    IScrollBarAnnotation,
    IXtraPartlyDeserializable
vb
Public NotInheritable Class CustomAxisLabel
    Inherits ChartElementNamed
    Implements ICustomAxisLabel,
               IAxisValueContainer,
               IScrollBarAnnotation,
               IXtraPartlyDeserializable

The following members return CustomAxisLabel objects:

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.

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 ChartElement ChartElementNamed CustomAxisLabel

See Also

CustomAxisLabel Members

CustomLabels

CustomAxisLabelCollection

Axis Labels

DevExpress.XtraCharts Namespace