Skip to main content

ChartControl.HitTest(Int32, Int32) Method

Returns specific chart elements, which are located under the test point.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v24.2.UI.dll

NuGet Package: DevExpress.Win.Charts

Declaration

public object[] HitTest(
    int x,
    int y
)

Parameters

Name Type Description
x Int32

An integer value that specifies the x coordinate of the test point.

y Int32

An integer value that specifies the y coordinate of the test point.

Returns

Type Description
Object[]

An array of Objects, that represent the chart elements located under the test point.

Remarks

A SeriesPoint isn’t a chart element. To get the current series point under the test point, you need to use the ChartControl.CalcHitInfo method and use the ChartHitInfo.SeriesPoint property.

Note

The HitTest method is supported in 2D charts only. It can’t be used for 3D charts.

Example

The following example handles the ChartControl.MouseMove event to identify the chart element under the mouse pointer and display its name in the form’s caption.

Note

Turn on the ChartControl.RuntimeHitTesting option to enable hit testing.

using DevExpress.XtraCharts;
using System.Windows.Forms;

namespace DXApplication {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            InitializeComponent();
            chartControl1.MouseMove += ChartControl1_MouseMove;
            chartControl1.RuntimeHitTesting = true;
        }

        void ChartControl1_MouseMove(object sender, MouseEventArgs e) {
            ChartHitInfo hi = chartControl1.CalcHitInfo(new System.Drawing.Point(e.X, e.Y));
            this.Text = hi.HitTest.ToString();
        }
    }
}
See Also