Back to Devexpress

AxisLabel.TextPattern Property

corelibraries-devexpress-dot-xtracharts-dot-axislabel.md

latest10.9 KB
Original Source

AxisLabel.TextPattern Property

Gets or sets a string that formats text for the auto-generated x- or y-axis labels.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
[XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)]
public string TextPattern { get; set; }
vb
<XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)>
Public Property TextPattern As String

Property Value

TypeDescription
String

The string that formats text for axis labels.

The default value is Empty.

|

Remarks

The following images show how various patterns affect the axis label text:

axisXLabel.TextPattern = “{A:dd-MM HH:mm}”, axisYLabel.TextPattern = “{V} °F”

axisYLabel.TextPattern = “{VP:P0}”

axisXLabel.TextPattern = “{A:0.0#}”, axisYLabel.TextPattern = “{V}°C”

axisXLabel.TextPattern = “{A:dd-MMM-yy}”, axisYLabel.TextPattern = “${V}”

axisXLabel.TextPattern = “{A:MMM}”, axisYLabel.TextPattern = “{V}°C”

The code below formats label text:

csharp
AxisLabel axisXLabel = ((XYDiagram)chartControl.Diagram).AxisX.Label;
AxisLabel axisYLabel = ((XYDiagram)chartControl.Diagram).AxisY.Label;

axisXLabel.TextPattern = "{A:dd-MM HH:mm}";
axisYLabel.TextPattern = "{V} °F";
vb
Dim axisXLabel As AxisLabel = CType(chartControl.Diagram,XYDiagram).AxisX.Label
Dim axisYLabel As AxisLabel = CType(chartControl.Diagram,XYDiagram).AxisY.Label
axisXLabel.TextPattern = "{A:dd-MM HH:mm}"
axisYLabel.TextPattern = "{V} °F"

Patterns can contain regular text (displayed as is) and value placeholders in braces. To format numeric and date/time values, you can apply Format Specifiers. Use a colon to separate a placeholder and its format specifier.

The following table contains the available placeholders:

PlaceholderDescription
Placeholders available for arguments’ axis
{A}Use it to display arguments.
Placeholders available for values’ axis
{V}Use it to display values.
{VP}Use it to display values as a percentage.

Note

To show year quarters for the date-time x-axis labels, use the “{A:q}” pattern.

You can use the Pattern Editor to specify the label text format. To invoke the editor, click the TextPattern property ellipsis button in the Properties window or in the Chart Designer.

Example

This example demonstrates how to customize axis labels’ text pattern. Axis labels use this pattern to provide text representation of axis values’ on which labels are located.

Use the following properties to access the text pattern:

PropertyDescription
Axis2D.LabelGets the settings of axis labels.
Axis3D.LabelGets the settings of axis labels in 3D series.
RadarAxisX.LabelGets the settings of axis labels.
RadarAxisY.LabelGets the settings of axis labels.
AxisLabel.TextPatternGets or sets a string that formats text for the auto-generated x- or y-axis labels.
csharp
using System;
using DevExpress.XtraCharts;

namespace LabelTextPatternSample {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);
            if (chartControl1.Diagram is XYDiagram xyDiagram) {
                xyDiagram.AxisX.Label.TextPattern = "Region: {A}";
                xyDiagram.AxisY.Label.TextPattern = "{VP:P0}";
            }
        }
        public Form1() {
            InitializeComponent();
        }
    }
}
vb
Imports DevExpress.XtraCharts

Public Class Form1
    Protected Overrides Sub OnLoad(e As EventArgs)
        MyBase.OnLoad(e)
        Dim xyDiagram = TryCast(ChartControl1.Diagram, XYDiagram)
        If (xyDiagram IsNot Nothing) Then
            xyDiagram.AxisX.Label.TextPattern = "{A}"
            xyDiagram.AxisX.Label.TextPattern = "{VP:P0}"
        End If
    End Sub
End Class

The following code snippets (auto-collected from DevExpress Examples) contain references to the TextPattern property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-charts-use-automatic-date-time-scale-modes-of-an-axis/CS/DateTimeAggregation/Form1.cs#L168

csharp
void SetYearMeasureUnit() {
    AxisX.Label.TextPattern = "{A:yyyy}";
    AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Year;

winforms-visualize-data-grid-rows-in-a-chart/CS/ControlRowSourceSample/MainForm.cs#L36

csharp
XYDiagram diagram = (XYDiagram)chartControl.Diagram;
diagram.AxisY.Label.TextPattern = "{V:C0}";

winforms-dashboard-obtain-dashboard-item-client-data/CS/Dashboard_ClientDataCards_Win/Form1.cs#L75

csharp
series2.ValueDataMembers.AddRange(new string[] { "Target" });
((XYDiagram)chart.Diagram).AxisY.Label.TextPattern = "{V:$0}";

winforms-charts-create-model-for-custom-chart-element/CS/CustomChartElementModel/Form1.cs#L128

csharp
XYDiagram diagram = chart.Diagram as XYDiagram;
diagram.AxisX.Label.TextPattern = "{A:MMM, d (HH:mm)}";
diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Hour;

winforms-charts-use-automatic-date-time-scale-modes-of-an-axis/VB/DateTimeAggregation/Form1.vb#L150

vb
Private Sub SetYearMeasureUnit()
    AxisX.Label.TextPattern = "{A:yyyy}"
    AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Year

winforms-visualize-data-grid-rows-in-a-chart/VB/ControlRowSourceSample/MainForm.vb#L33

vb
Dim diagram As XYDiagram = CType(chartControl.Diagram, XYDiagram)
diagram.AxisY.Label.TextPattern = "{V:C0}"
chartControl.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right

winforms-dashboard-obtain-dashboard-item-client-data/VB/Dashboard_ClientDataCards_Win/Form1.vb#L75

vb
series2.ValueDataMembers.AddRange(New String() { "Target" })
CType(chart.Diagram, XYDiagram).AxisY.Label.TextPattern = "{V:$0}"

winforms-charts-create-model-for-custom-chart-element/VB/CustomChartElementModel/Form1.vb#L186

vb
Dim diagram As XYDiagram = TryCast(chart.Diagram, XYDiagram)
diagram.AxisX.Label.TextPattern = "{A:MMM, d (HH:mm)}"
diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Hour

See Also

LegendTextPattern

Format Text Chart Elements

AxisLabel Class

AxisLabel Members

DevExpress.XtraCharts Namespace