WPF Charting Documentation - SciChart WPF Charts SDK v5.x
RenderableSeries Hit-Test API

Hit-Testing Series

The Hit-Test API is set of virtual methods defined on BaseRenderableSeries, and overridden by some of the series types. This API is used by the RolloverModifierSeriesSelectionModifier and TooltipModifier to transform mouse-clicks into data-points, and determine if a mouse-point is over a point or over a series.

 

To call the Hit-Test method, use the following code:

Example Title
Copy Code
// Subscribed using this code:
// sciChartSurface.MouseLeftButtonUp += SciChartSurfaceMouseLeftButtonUp;
private void SciChartSurfaceMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    // Perform the hit test relative to the GridLinesPanel
    Point mousePoint = e.GetPosition(sciChartSurface.GridLinesPanel as UIElement);
    double datapointRadius = 8;
    bool useInterpolation = false;
    HitTestInfo result = sciChartSurface.RenderableSeries[0].HitTest(mousePoint,
                                      datapointRadius, useInterpolation);

    // Output results
    string formattedString =
        string.Format(
            "{6}:\tMouse Coord: {0:0}, {1:0}\t\tNearest Datapoint Coord: {2:0.0},
                                  {3:0.0}\tData Value: {4:0.0}, {5:0.0}",
            mousePoint.X, mousePoint.Y,
            result.HitTestPoint.X, result.HitTestPoint.Y,
            result.XValue, result.YValue,
            result.DataSeriesName);

    Console.WriteLine(formattedString);
}

NOTE: You must transform any mouse-points into the coordinate space of the main chart area. Above we use the GridLinesPanel, which is a canvas in the centre of the chart viewport (inside the axes). Without this, all hit-test results will be inaccurate.

The HitTestInfo Result

The HitTestInfo struct has many properties which are useful to determine what was under the mouse. For instance:

HitTestInfo Property

Description

NameDataSeries

The DataSeries.SeriesName of the DataSeries instance that was hit.

HitTestPoint

A Point snapped to the X-Y coordinate of the series

Y1HitTestPoint

A point snapped to the X-Y1 coordinate (in case of XyyDataSeries) of the series

XValue

The DataSeries X-Value nearest to the Hit-Test Site

YValue

The DataSeries Y-Value nearest to the Hit-Test Site

Y1Value

The DataSeries Y1-Value (in case of XyyDataSeries) nearest to the Hit-Test Site

ZValue

The DataSeries Z-Value (in case of XyzDataSeries) nearest to the Hit-Test Site

DataSeriesIndex

The index to the DataSeries.XValues, YValues nearest to the Hit-Test Site

IsHit

A Boolean flag which is True if the mouse-point was within a certain radius of an X-Y point on a series.

IsVerticalHit

A Boolean flag which is True if the mouse-point was within a certain radius of an X point on a series.

IsWithinDataBounds

A Boolean flag which is true if the mouse-point is between the first and last DataSeries value or not.

ErrorHigh

The DataSeries ErrorHigh-Value (in case of HLCDataSeries) nearest to the Hit-Test Site

ErrorLow

The DataSeries ErrorLow-Value (in case of HLCDataSeries) nearest to the Hit-Test Site

OpenValue

The DataSeries Open-Value (in case of OhlcDataSeries) nearest to the Hit-Test Site

HighValue

The DataSeries High-Value (in case of OhlcDataSeries) nearest to the Hit-Test Site

LowValue

The DataSeries Low-Value (in case of OhlcDataSeries) nearest to the Hit-Test Site

CloseValue

The DataSeries Close-Value (in case of OhlcDataSeries) nearest to the Hit-Test Site

Minimum

The DataSeries Minimum-Value (in case of BoxPlotDataSeries) nearest to the Hit-Test Site

Maximum

The DataSeries Maximum-Value (in case of BoxPlotDataSeries) nearest to the Hit-Test Site

Median

The DataSeries Median-Value (in case of BoxPlotDataSeries) nearest to the Hit-Test Site

LowerQuartile

The DataSeries LowerQuartile-Value (in case of BoxPlotDataSeries) nearest to the Hit-Test Site

UpperQuartile

The DataSeries UpperQuartile-Value (in case of BoxPlotDataSeries) nearest to the Hit-Test Site

Percentage

The percentage value (in case of StackedColumnRenderableSeries with Is100Percent flag set to true).

IsEmpty()

Returns a Boolean value if the HitTestInfo struct is default (defined as empty)

 

UseInterpolation Flag

The UseInterpolation flag increases the accuracy of HitTest at the expense of performance.

When used in a FastLineRenderableSeries, UseInterpolation=True will return IsHit=True if the input mouse-point is over the line, whereas if UseInterpolation=False, it will return IsHit=True only if the input mouse-point is over a data-point.

This is useful say if you wanted to show a tooltip only on datapoints (UseInterpolation=False), vs. a click event anywhere on the line (UseInterpolation=True).

For other series types, such as FastCandlestickRenderableSeriesFastColumnRenderableSeriesFastMountainRenderableSeries, setting UseInterpolation=True will result in an IsHit=True when the mouse is ‘over the series’ as opposed to ‘over the data-points’.

NOTE: Interpolation is linear interpolation and at the time of writing, is not suitable for use by Logarithmic Axis.

 

See Also

 

 


SCICHART ® is a Registered Trademark in the UK, US and EEC. Copyright SciChart Ltd 2011-2018.

Email us to give feedback!