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

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

  • 3 minutes to read

This example demonstrates how to handle the ChartControl.MouseMove event, to determine which series point is located under the test point and display information about its argument and value using ToolTipController.

To enable hit testing at runtime so that this example works correctly, make sure that the ChartControl.RuntimeHitTesting property is set to true.

View Example

using System;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraCharts;
// ...
        private void Form1_Load(object sender, EventArgs e) {
            chartControl1.CrosshairEnabled = DefaultBoolean.False;
            chartControl1.RuntimeHitTesting = true;
        }


        private void chartControl1_MouseMove(object sender, MouseEventArgs e) {
            // Obtain hit information under the test point.
            ChartHitInfo hi = chartControl1.CalcHitInfo(e.X, e.Y);

            // Obtain the series point under the test point.
            SeriesPoint point = hi.SeriesPoint;

            // Check whether the series point was clicked or not.
            if (point != null) {
                // Obtain the series point argument.
                string argument = "Argument: " + point.Argument.ToString();

                // Obtain series point values.
                string values = "Value(s): " + point.Values[0].ToString();
                if (point.Values.Length > 1) {
                    for (int i = 1; i < point.Values.Length; i++) {
                        values = values + ", " + point.Values[i].ToString();
                    }
                }

                // Show the tooltip.
                toolTipController1.ShowHint(argument + "\n" + values, "SeriesPoint Data");
            }
            else {
                // Hide the tooltip.
                toolTipController1.HideHint();
            }
        }

The ChartControl.HitTest method cannot be used for that purpose since it returns the ChartElement clicked by the mouse. The SeriesPoint object is not a chart element, while the Series, XYDiagram, ChartControl are.

The result is shown in the following image.

howTo_point-hit-testing

See Also