Skip to main content

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.
  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 https://supportcenter.devexpress.com/ticket/details/e126/how-to-show-a-tooltip-with-a-series-point-s-data.

See Also