corelibraries-devexpress-dot-xtracharts-dot-axislabel.md
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
[XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)]
public string TextPattern { get; set; }
<XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)>
Public Property TextPattern As String
| Type | Description |
|---|---|
| String |
The string that formats text for axis labels.
The default value is Empty.
|
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:
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";
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:
| Placeholder | Description |
|---|---|
| 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.
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:
| Property | Description |
|---|---|
| Axis2D.Label | Gets the settings of axis labels. |
| Axis3D.Label | Gets the settings of axis labels in 3D series. |
| RadarAxisX.Label | Gets the settings of axis labels. |
| RadarAxisY.Label | Gets the settings of axis labels. |
AxisLabel.TextPattern | Gets or sets a string that formats text for the auto-generated x- or y-axis labels. |
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();
}
}
}
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
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
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
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
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
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
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
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
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