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

0
0

Hello,

I want to implement a custom deltaX cursor in my software. It consists in two vertical lines that can be moved be the user and the idea to get the delta x (DateTime) between the two lines.
I’ve started to implement it by using two custom VerticalLineAnnotation added to a VerticalSliceManager. As my chart is a real time chart, I don’t want my cursors postions changed exepct on user interaction, that’s why I set to Relative the CoordinateMode property of my two Annotations.
The display and the interaction works fine, but when I try to retrieve the actual position of one cursor to compute the delta I have some trouble to convert the relative position to a DateTime value.
I have override the OnDragDelta() method, the relative value of X1 is correct but when I try to convert it into a DateTime by using FromRelativeCoordinate, I still have Date in 1899. I also try to interpret this as OA Date but I still have wrong date.

Do you have an idea ?
Thanks

 public override void OnDragDelta()
    {
        if (_sciChartSurface.XAxis != null)
        {
            double dataValue = (double)this.FromRelativeCoordinate((double)this.X1, _sciChartSurface.XAxis);
            DateTime classic = new DateTime((long)dataValue);
            DateTime fromOa = DateTime.FromOADate(dataValue);
            Debug.WriteLine("CLASSIC "+ classic);
            Debug.WriteLine("OA "+ fromOa);
        }
    }
Version
6.2.0.13254
  • You must to post comments
1
0

Hi Jean-Charles

What you need to do is get the pixel-coordinate of the VerticalLineAnnotation in the X-direction, then use the Axis APi to convert to DataValue.

I think this can be done with:

 double pixelCoordX = Canvas.GetLeft(verticalLineAnnotation);
 DateTime dataValue = (DateTime)xAxis.GetDataValue(pixelCoordX);

but haven’t tested it. Can you try it and let me know if that works?

  • Jean-Charles DURAND
    Hello Andrew, Thanks for the quick answer. Your solution works fine, I just tweaked it a little by adding the half of the Annotation width to have the correct value. Thanks again for the support.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.