Back to Devexpress

CustomAxisLabel.AxisValue Property

corelibraries-devexpress-dot-xtracharts-dot-customaxislabel.md

latest4.3 KB
Original Source

CustomAxisLabel.AxisValue Property

Gets or sets the custom label’s position along an axis.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
[XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)]
public object AxisValue { get; set; }
vb
<XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)>
Public Property AxisValue As Object

Property Value

TypeDescription
Object

A floating point value that specifies the custom label’s position.

|

Remarks

The AxisValue property specifies the position of the custom label along its corresponding axis. The value set for the AxisValue property should lie in the range specified by the AxisBase.WholeRange or AxisBase.VisualRange property in order for the custom label to be visible on a diagram.

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

See Also

Axis Labels

CustomAxisLabel Class

CustomAxisLabel Members

DevExpress.XtraCharts Namespace