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.v19.2.UI.dll
Declaration
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 |
---|---|
ChartHitInfo | A ChartHitInfo object which contains information about the chart elements located at the test point. |
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 ChartControl.RuntimeHitTesting property is set to true.
This method is supported for 2D Chart Types only. So, hit testing for 3D Chart Types isn’t supported in the current version of XtraCharts.
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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-determine-which-series-point-is-located-under-the-test-point-e2717
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();
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CalcHitInfo(Int32, Int32) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.