Skip to main content
A newer version of this page is available. .

How to: Show Custom Information in a Crosshair Cursor Tooltip

  • 3 minutes to read

This example demonstrates how to display custom information from the underlying datasource in a crosshair cursor tooltip for every series point.

For this example to work correctly, do the following.

  1. Start MS Visual Studio (2008, 2010 or 2012).
  2. Create a new Windows Forms Application, or open an existing one.
  3. Drop the ChartControl onto the form.
  4. Add a single Bar Series to the chart, then bind it to the Products table from the nwind.mdb database (see Lesson 3 - Bind Chart Series to Data to learn how to do this).
  5. Set the series’ SeriesBase.ArgumentDataMember property to ProductName and its SeriesBase.ValueDataMembers.Value property to UnitPrice.
  6. Then handle the ChartControl.CustomDrawCrosshair event, as shown in the code below.
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraCharts;

namespace CustomInfoInTooltips {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            // This line of code loads data into the 'nwindDataSet.Products' table. You can move, or remove it, as needed.
            this.productsTableAdapter.Fill(this.nwindDataSet.Products);

        }

        private void chartControl1_CustomDrawCrosshair(object sender, CustomDrawCrosshairEventArgs e) {
            foreach (CrosshairElement element in e.CrosshairElements) {
                {
                    SeriesPoint currentPoint = element.SeriesPoint;

                    if (currentPoint.Tag.GetType() == typeof(DataRowView)) {
                        DataRowView rowView = (DataRowView)currentPoint.Tag;
                        string s = "Unit price = " + rowView["UnitPrice"].ToString() +
                            "\r\nUnits in stock = " + rowView["UnitsInStock"].ToString() +
                            "\r\nQuantity per unit = " + rowView["QuantityPerUnit"].ToString();

                        element.LabelElement.Text = s;

                    }
                }
            }
        }
    }
}

The result of executing this code is shown in the following image.

ShowSeriesPointTooltip

Tip

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

See Also