Back to Devexpress

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

windowsforms-3248-controls-and-libraries-chart-control-examples-end-user-interaction-how-to-determine-which-series-point-is-under-the-test-point.md

latest5.1 KB
Original Source

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

  • Apr 04, 2025
  • 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.

csharp
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();
            }
        }
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.Utils
Imports DevExpress.XtraCharts
' ...
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            chartControl1.CrosshairEnabled = DefaultBoolean.False
            chartControl1.RuntimeHitTesting = True
        End Sub

        Private Sub chartControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles chartControl1.MouseMove
            ' Obtain hit information under the test point.
            Dim hi As ChartHitInfo = chartControl1.CalcHitInfo(e.X, e.Y)

            ' Obtain the series point under the test point.
            Dim point As SeriesPoint = hi.SeriesPoint

            ' Check whether the series point was clicked or not.
            If point IsNot Nothing Then
                ' Obtain the series point argument.
                Dim argument As String = "Argument: " & point.Argument.ToString()

                ' Obtain series point values.
                Dim values As String = "Value(s): " & point.Values(0).ToString()
                If point.Values.Length > 1 Then
                    For i As Integer = 1 To point.Values.Length - 1
                        values = values & ", " & point.Values(i).ToString()
                    Next i
                End If

                ' Show the tooltip.
                toolTipController1.ShowHint(argument & ControlChars.Lf & values, "SeriesPoint Data")
            Else
                ' Hide the tooltip.
                toolTipController1.HideHint()
            End If
        End Sub

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.

See Also

CalcHitInfo

HitTest

HitInfo

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

How to: Determine a Chart Element the Mouse Pointer Hovers Over