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

  • 2 minutes to read

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

ShowSeriesPointTooltip

  1. Run Microsoft Visual Studio 2012, 2013, 2015, 2017 or 2019.
  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}".
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}";
        }
    }
}
TIP

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E126.

See Also