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

ChartHitInfo Class

Contains information about a specific point within a chart.

Namespace: DevExpress.Xpf.Charts

Assembly: DevExpress.Xpf.Charts.v19.2.dll

Declaration

public class ChartHitInfo :
    ChartHitInfoBase

The following members return ChartHitInfo objects:

Remarks

ChartHitInfo objects can be created by calling the chart’s ChartControl.CalcHitInfo method. This method requires the test point as a parameter, or its coordinates.

The ChartHitInfo class properties can be grouped into two categories:

  • The properties that indicate whether the test point resides over a particular view element. For instance, the ChartHitInfoBase.InAxis property indicates whether the test point is over the axis;
  • The properties identifying the topmost visual element, which contains the test point (e.g. ChartHitInfoBase.Axis).

Example

This example demonstrates how to calculate the hit information for the chart element over which the mouse pointer is hovering.

To accomplish this, handle the ChartControl.MouseMove event, obtain the current chart element via the ChartControl.CalcHitInfo method, and if the element is not null (Nothing in Visual Basic), display its information.

using System.Windows;
using System.Windows.Input;
using DevExpress.Xpf.Charts;
using System.Text;

namespace DetermineHoveredChartElement
{

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void chartControl1_MouseMove(object sender, MouseEventArgs e)
        {
            // Obtain hit information under the test point.
            ChartHitInfo hitInfo = chartControl1.CalcHitInfo(e.GetPosition(chartControl1));
            StringBuilder builder = new StringBuilder();

            // Check  whether the chart element is under the test point and if so - obtain the element's content.
            if (hitInfo.InDiagram)
                builder.AppendLine("In diagram");
            if (hitInfo.InAxis)
                builder.AppendLine("In axis:" + hitInfo.Axis.Name);
            if (hitInfo.AxisLabel != null)
                builder.AppendLine("Axis Label:\n" + hitInfo.AxisLabel.Name);
            if (hitInfo.AxisTitle != null)
                builder.AppendLine("Axis title:\n" + hitInfo.AxisTitle.Content);
            if (hitInfo.InTitle)
                builder.AppendLine("In chart title:\n " + hitInfo.Title.Content);
            if (hitInfo.InLegend)
                builder.AppendLine("In legend");
            if (hitInfo.InSeries)
                builder.AppendLine("In series: " + hitInfo.Series.Name);
            if (hitInfo.InSeriesLabel)
            {
                builder.AppendLine("In series label");
                builder.AppendLine("Series Label:" + hitInfo.SeriesLabel.Name);
            }

            if (hitInfo.InSeriesPoint)
            {
                builder.AppendLine("Argument: " + hitInfo.SeriesPoint.Argument);
                builder.AppendLine("Value: " + hitInfo.SeriesPoint.Value);
            }

            // Show hit-testing results 
            if (builder.Length > 0)
                text1.Content = string.Format("Hit-testing results:\n" + builder.ToString());
            else
                text1.Content = "Move the mouse\n pointer over\n the chart to see\n information on\n hovered chart\n elements.";
        }
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ChartHitInfo class.

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.

Inheritance

See Also