Back to Devexpress

CrosshairOptions.GroupHeaderPattern Property

corelibraries-devexpress-dot-xtracharts-dot-crosshairoptions-7372f627.md

latest11.8 KB
Original Source

CrosshairOptions.GroupHeaderPattern Property

Gets or sets a pattern that specifies the group header text to be displayed within the crosshair label.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
public string GroupHeaderPattern { get; set; }
vb
Public Property GroupHeaderPattern As String

Property Value

TypeDescription
String

The group header’s pattern.

|

Property Paths

You can access this nested property as listed below:

LibraryObject TypePath to GroupHeaderPattern
WinForms ControlsChartControl

.CrosshairOptions .GroupHeaderPattern

| | ASP.NET MVC Extensions | ChartControlSettings |

.CrosshairOptions .GroupHeaderPattern

| | ASP.NET Web Forms Controls | WebChartControl |

.CrosshairOptions .GroupHeaderPattern

|

Remarks

GroupHeaderPattern can contain plain text and placeholders with format specifiers. The following placeholders are available:

PlaceholderDescription
{A}Displays an argument. CrosshairOptions.SnapMode should be set to NearestArgument.
{V}Displays a value. CrosshairOptions.SnapMode should be set to NearestValue.

The following image shows this property in action with the “Year: {A}” pattern.

You can use the Pattern Editor to specify the pattern. Click the GroupHeaderPattern property’s ellipsis button in the Properties window to invoke the editor.

Note

A crosshair group header is not displayed on the crosshair label when the CrosshairOptions.CrosshairLabelMode property is set either to CrosshairLabelMode.ShowForEachSeries or CrosshairLabelMode.ShowForNearestSeries modes and when the crosshair is only allowed for a single series. Specify GroupHeaderPattern to make the Crosshair Cursor always show group headers.

See the Crosshair Cursor topic for more information.

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

csharp
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);
        }

    }
}
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts

Namespace FormatCrosshairLabels
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            AddHandler Load, AddressOf Form1_Load
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
            ' Create an empty chart.
            Dim chartControl1 As New ChartControl()

            ' Create a first line series and add points to it.
            Dim series1 As 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.
            Dim series2 As 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.
            Dim diagram As XYDiagram = CType(chartControl1.Diagram, XYDiagram)

            ' 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
            Me.Controls.Add(chartControl1)
        End Sub

    End Class
End Namespace

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GroupHeaderPattern 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-chart-format-values-in-a-crosshair-cursor-with-a-labels-patterns/VB/FormatCrosshairLabels/Form1.vb#L49

vb
' Specify the crosshair group header pattern.
chartControl1.CrosshairOptions.GroupHeaderPattern = "Year: {A}"
' Cast the chart's diagram to the XYDiagram type, to access its axes.

See Also

Format Text Chart Elements

CrosshairOptions Class

CrosshairOptions Members

DevExpress.XtraCharts Namespace