Pre loader

converting x axis data to DateTime

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

hi,
I’m trying to convert the current mouse X position to the DataTime of the data series the mouse is over:

        Point mousePoint = e.GetPosition(view.ChartSurface.ModifierSurface as UIElement);
        //var mouseDate = (DateTime)view.ChartSurface.XAxis.GetDataValue(mousePoint.X);
        ICoordinateCalculator<double> calc = view.ChartSurface.XAxis.GetCurrentCoordinateCalculator();
        double mouseDataValue = calc.GetDataValue(mousePoint.X);            
        var mouseDate = DateTime.FromOADate(mouseDataValue);

mouseDataValue returns the correct index of the data, but mouseDate always converts to the year 1900.
thanks!

  • You must to post comments
0
0

Hi there,

I assume that you use CategoryDateTimeAxis because calc.GetDataValue(mousePoint.X) return data index. In this case you should convert index to data value using the same CoordinateCalculator object:

            var categoryCoordCalc = view.ChartSurface.XAxis.GetCurrentCoordinateCalculator() as ICategoryCoordinateCalculator;

            var dataPointIndex = categoryCoordCalc.GetDataValue(mousePoint.X);
            var xDataValue = categoryCoordCalc.TransformIndexToData(dataPointIndex);

            var mouseDate = DateTime.FromOADate(xDataValue);

Please, let us know if this helps!

Best regards,
Yuriy

  • tecman234
    Yuriy, Your suggestion worked with just a little type conversion tweak, and since the xDataValue is already a DateTime, I didn't neeed the FromOADate conversion. The final code is:
                Point mousePoint = e.GetPosition(view.ChartSurface.ModifierSurface as UIElement);
    
                var categoryCoordCalc = view.ChartSurface.XAxis.GetCurrentCoordinateCalculator() as ICategoryCoordinateCalculator;
    
                var dataPointIndex = (int)categoryCoordCalc.GetDataValue(mousePoint.X);
                var mouseDate = categoryCoordCalc.TransformIndexToData(dataPointIndex);
    Thanks for the help!
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies