I am trying to convert mouse event args to a date/time from the categoryXAxis. When I tried to convert the x value to dateTime, it is setting the year (in all instances), to 1900.
Point position = e.GetPosition(s);
LineSeries ls = s as LineSeries;
CategoryXAxis x = ls.XAxis as CategoryXAxis;
NumericYAxis y = ls.YAxis;
Rect viewport = new Rect(0, 0, x.ActualWidth, y.ActualHeight);
Rect window = s.SeriesViewer.WindowRect;
bool isInverted = x.IsInverted;
ScalerParams param = new ScalerParams(window, viewport, isInverted);
var unscaledX = x.GetUnscaledValue(position.X, param);
isInverted = y.IsInverted;
param = new ScalerParams(window, viewport, isInverted);
var unscaledY = y.GetUnscaledValue(position.Y, param);
DateTime xValue = DateTime.FromOADate(unscaledX);
double yValue = Convert.ToDouble(unscaledY);
Hello Keicha,
Thank you for your email. I have been looking into the question that you are having and when using a CategoryXAxis, the GetUnscaledValue method is returning a value between 0 and the count of items in the axis’ ItemsSource, since the CategoryXAxis is arranging the items in its ItemsSource based on their index. You can use the GetUnscaledValue to get the index of the CategotyXAxis’ ItemsSource and then get the Date from the item. Using this approach will get only the values for the items in the ItemsSource and if you hover between two points it will show the value to the closes point to the mouse.
If you wish to get the specific value based on the mouse position, I can suggest using CategoryDateTimeXAxis instead. The GetUnscaledValue method of the CategoryDateTimeXAxis returns a double value, that corresponds to the Ticks of the DateTime at the given point and you can convert this to a DateTime. I have created a sample application for you, that shows how you can implement both of the approaches.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir, MCPD
Developer Support Supervisor - XAML
Infragistics
www.infragistics.com/support
I am just checking if you require any further assistance on the matter.