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!

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.