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!
- tecman234 asked 11 years ago
- You must login to post comments
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
- Yuriy Zadereckiy answered 11 years ago
-
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 login to post comments
Please login first to submit.