CrosshairAxisLabelOptions.Pattern Property
Gets or sets a string which represents the pattern specifying the text to be displayed within the crosshair axis label that appears for a series point.
Namespace: DevExpress.XtraCharts
Assembly: DevExpress.XtraCharts.v24.2.dll
Declaration
[XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)]
public string Pattern { get; set; }
Property Value
Type | Description |
---|---|
String | A String that is the crosshair axis label pattern. The default value is Empty. |
Property Paths
You can access this nested property as listed below:
Object Type | Path to Pattern |
---|---|
Axis2D |
|
Remarks
You can use either the {A} pattern for the X-axis, or the {V} pattern for the Y-axis, together with the Format Specifiers.
You can also specify a pattern using the Pattern Editor (the editor is invoked by clicking the ellipsis button of the Pattern property in the Properties window).
For example, the table below shows {V:F0} and {V:F4} patterns that are used to format crosshair value labels.
Pattern= {V:F0} | Pattern= {V:F4} |
---|---|
The table below demonstrates the {A:F0} and {A:F4} patterns that format crosshair argument labels.
Pattern= {A:F0} | Pattern= {A:F4} |
---|---|
Note
When you format crosshair axis labels, they can demand more space on a diagram to display the whole axis value. To extend the space for a crosshair axis label, the AxisLabel.BeginText property should contain empty spaces that correspond the required area for the crosshair axis labels.
You can use standard and custom format specifies, together with the placeholders to format numeric and date/time values (e.g., {V:F0}). To learn more, see the Format Specifiers topic.
For more information on how to use a crosshair cursor, refer to the Tooltip and Crosshair Cursor topic.
Example
This example demonstrates how to change a text displayed in crosshair labels using crosshair format patterns.
To accomplish this, it is necessary to specify a string which will represent the pattern displayed within a crosshair label using the CrosshairAxisLabelOptions.Pattern
, SeriesBase.CrosshairLabelPattern, and CrosshairOptions.GroupHeaderPattern properties.
In addition, standard and custom format specifiers are used together with the placeholders to format numeric and date/time values (e.g., “{A:F0}”). To learn more, see the Format Specifiers topic.
To learn more on crosshair cursors, see the Tooltip and Crosshair Cursor topic.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/winforms-chart-format-values-in-a-crosshair-cursor-with-a-labels-patterns
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
namespace FormatCrosshairLabels
{
public partial class Form1 : Form
{
public Form1()
{
this.Load += new System.EventHandler(this.Form1_Load);
}
private void Form1_Load(object sender, EventArgs e)
{
// Create an empty chart.
ChartControl chartControl1 = new ChartControl();
// Create a first line series and add points to it.
Series series1 = new Series("Europe", ViewType.Line);
series1.Points.Add(new SeriesPoint(1950, 546));
series1.Points.Add(new SeriesPoint(1960, 605));
series1.Points.Add(new SeriesPoint(1970, 656));
series1.Points.Add(new SeriesPoint(1980, 694));
series1.Points.Add(new SeriesPoint(1990, 721));
series1.Points.Add(new SeriesPoint(2000, 730));
series1.Points.Add(new SeriesPoint(2010, 728));
// Create a second line series and add points to it.
Series series2 = new Series("Americas", ViewType.Line);
series2.Points.Add(new SeriesPoint(1950, 332));
series2.Points.Add(new SeriesPoint(1960, 417));
series2.Points.Add(new SeriesPoint(1970, 513));
series2.Points.Add(new SeriesPoint(1980, 614));
series2.Points.Add(new SeriesPoint(1990, 721));
series2.Points.Add(new SeriesPoint(2000, 836));
series2.Points.Add(new SeriesPoint(2010, 935));
// Add the series to the chart.
chartControl1.Series.Add(series1);
chartControl1.Series.Add(series2);
// Hide the legend (if necessary).
chartControl1.Legend.Visible = false;
//Show crosshair axis lines and crosshair axis labels to see format values of crosshair labels
chartControl1.CrosshairOptions.ShowArgumentLabels = true;
chartControl1.CrosshairOptions.ShowValueLabels = true;
chartControl1.CrosshairOptions.ShowValueLine = true;
chartControl1.CrosshairOptions.ShowArgumentLine = true;
// Specify the crosshair label pattern for both series.
series1.CrosshairLabelPattern = "{S} population: {V}";
series2.CrosshairLabelPattern = "{S} population: {V}";
// Specify the crosshair group header pattern.
chartControl1.CrosshairOptions.GroupHeaderPattern = "Year: {A}";
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
// Specify the crosshair axis labels pattern for X-axis.
diagram.AxisX.CrosshairAxisLabelOptions.Pattern = "Year: {A:F0}";
// Add the chart to the form.
chartControl1.Dock = DockStyle.Fill;
this.Controls.Add(chartControl1);
}
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Pattern 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.