SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

Answered
1
0

Hi,

I have a dataseries I need to display on a log Axis – i have stripped out the <= 0 Y values and replaced them with NaN’s and set the chart to draw NaN’s as gaps which is all working as expected. The axis is a datetime x-axis and I’m plotting several Scatterseries on it.
I have a VerticalSliceModifier which the user sets to a particular point and the X value of that point is used to acquire further information from the database so for this feature the Y value is of no interest. I’ve overridden the MoveAnnotationTo() method in order to get the slicemodfier to “snap” to the next nearest point of any of the series shown.In order to do this I use :

HitTestInfo hitTestResult = _seriesToSnapTo.VerticalSliceHitTest(new Point(coordinates.X1Coord + horizOffset, 1));

The problem is that if the point is one of those with a Y Value of NaN the HitTestResult comes back as everything being “null” and I can’t get the XAxis Value i need.

I would have expected the HitTest to have returned an X value regardless of the Y value being a NaN. I really just want to snap to the next X Axis point ignoring the Y value. Is there something else I should be using to get the next X-axis point I need?

  • You must to post comments
Best Answer
0
0

Hi Stuart,

I had a look at the Hit-Test code and because of the number of use-cases it has to satisfy (being fast, accurate, for many series types, on polar or normal charts, on data-points or interpolated) the code is pretty dense. I don’t really want to go in there and modify to output a value for Y=NaN (when some aspects of SciChart also rely on this, like Rollover, which should hide when Y=NaN).

However, I have a workaround for you so you can snap to the X-value and hopefully with only a few lines of code. Try this:

// Given an X-coordinate in pixels
double xCoord;

// Convert to X-data
double xData = _seriesToSnapTo.XAxis.GetDataValue(xCoord);

// Find the index nearest to the data
int index = _seriesToSnapTo.DataSeries.FindIndex(xData, SearchMode.FindNearest);

// If in range
if (index >= 0 && index < _seriesToSnapTo.DataSeries.Count)
{
     // Find data-value at snapped index
     double xDataSnapped = _seriesToSnapTo.DataSeries.XValues[index];

     // Find coordinate at snapped index
     double xCoordSnapped = _seriesToSnapTo.XAxis.GetCoordinate(xDataSnapped);
}

There, that’s a simple implementation of X-only Hit-Test and should work for snapping the VerticalLineAnnotation to a data-point!

Let me know if it works!

Best regards,
Andrew

  • Stuart McCullough
    Hi Andrew. i know how you feel about code complexity :-( I was happy enough for the Yvalue to come back as null or whatever, I was just surprised under these conditions what should have been a perfectly valid X value, was also coming back as a null.Anyway - your workaround works perfectly well thank you very much. I shall use your method :-)
  • Andrew
    It's mainly to do with - I don't know what else depends on that. I know for a fact Rollover is designed to disappear if the Y-Value is null because the series is also invisible at those points. I agree with you the behaviour of HitTest when Y=NaN is not intuitive but I don't want to change it when the above works perfectly well. Let me know if the issue is resolved! Best regards, Andrew
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.