Back to Devexpress

How to: Show Information from a Datasource Field in a Crosshair Cursor Label

windowsforms-3440-controls-and-libraries-chart-control-examples-end-user-interaction-how-to-show-custom-information-in-a-crosshair-cursor-tooltip.md

latest4.6 KB
Original Source

How to: Show Information from a Datasource Field in a Crosshair Cursor Label

  • Jul 17, 2025
  • 2 minutes to read

This example demonstrates how to display information from the underlying datasource in the Crosshair Cursor label for every series point.

  1. Run Microsoft Visual Studio.
  2. Create a new Windows Forms Application or open an existing project.
  3. Drop the ChartControl onto the form.
  4. Add a Bar Series to the chart. Bind it to the Products table from the nwind.mdb database (see Lesson 3 - Bind Chart Series to Data for details on how to do this).
  5. Set the SeriesBase.ArgumentDataMember property to ProductName and SeriesBase.ValueDataMembers .Value to UnitPrice.
  6. Use the SeriesBase.CrosshairLabelPattern property to format the crosshair label’s content. You can enclose the datasource field names in braces instead of default placeholders. For example: “Unit price: {UnitPrice}”.
csharp
using System;
using System.Windows.Forms;
namespace CustomInfoInTooltips {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e) {
            // TODO: This line of code loads data into the 'nwindDataSet.Products' table. You can move or remove it.
            this.productsTableAdapter.Fill(this.nwindDataSet.Products);

            chartControl1.Series[0].CrosshairLabelPattern = "Unit price: {UnitPrice}\r\n" +
                                                            "Units in stock: {UnitsInStock}\r\n" +
                                                            "Quantity per unit: {QuantityPerUnit}";
        }
    }
}
vb
Imports System
Imports System.Windows.Forms
Namespace CustomInfoInTooltips
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
            ' TODO: This line of code loads data into the 'nwindDataSet.Products' table. You can move or remove it.
            Me.productsTableAdapter.Fill(Me.nwindDataSet.Products)
            chartControl1.Series(0).CrosshairLabelPattern = "Unit price: {UnitPrice}" & vbCrLf &
                                                            "Units in stock: {UnitsInStock}" & vbCrLf &
                                                            "Quantity per unit: {QuantityPerUnit}"
        End Sub
    End Class
End Namespace

Tip

A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e126/winforms-chart-display-data-source-values-in-crosshair-labels.

See Also

How to: Determine which Series Point Is Under the Test Point

How to: Show Custom Data in a Web Chart Using ASPxPopupControl

How to: Show Series Labels Only for Hot-tracked Points

How to: Create a Text Annotation Anchored to a Series Point