ChartControl.CalcHitInfo(Int32, Int32) Method
Returns information on the chart elements located at the point with the specified x and y coordinates.
Namespace: DevExpress.XtraCharts
Assembly: DevExpress.XtraCharts.v24.2.UI.dll
NuGet Package: DevExpress.Win.Charts
#Declaration
public ChartHitInfo CalcHitInfo(
int x,
int y
)
#Parameters
Name | Type | Description |
---|---|---|
x | Int32 | An integer value which specifies the x-coordinate of the test point relative to the chart’s top-left corner. |
y | Int32 | An integer value which specifies the y-coordinate of the test point relative to the chart’s top-left corner. |
#Returns
Type | Description |
---|---|
Chart |
A Chart |
#Remarks
Use the CalcHitInfo method to determine which element is located at the point with the specified x and y coordinates. For instance, this can be used when handling the chart’s Click event to determine which element was clicked. In such cases, pass the current mouse pointer’s coordinates as the method’s parameter.
Important
To enable hit testing at runtime so that this example works correctly, make sure that the Chart
This method is supported for 2D Chart Types only. So, hit testing for 3D Chart Types isn’t supported in the current version of Xtra
#Example
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.
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();
}
}