Hi.
I'm have a chart showing points over time using CategoryDateTimeXAxis.
I want to get the following behavior:
if user click on a series data point, the application should identify that and do something (let's say show a message box with the x and y values)
else show the y value, converted to datetime.
I have the following code that give me the y value based on the axis, but how can I get the first request also?
private void timeline_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { MoveNavBar(e); } private void MoveNavBar(MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { var position = e.GetPosition(axisX); //we var x = timeline.Axes.OfType<CategoryDateTimeXAxis>().First(); var viewport = new Rect(0, 0, x.ActualWidth, 0); var window = timeline.WindowRect; ScalerParams sp = new ScalerParams(window, viewport, false); var unscaledX = x.GetUnscaledValue(position.X, sp); DateTime selectedTime = new DateTime((long)unscaledX); NavigationController.SetDate(selectedTime, this); } }
Thanks!
Hello eligazit,
Yes, that is correct. If you set the e.Handled argument to "true" in the SeriesMouseLeftButton down event, the MouseLeftButtonDown event of the XamDataChart will not fire.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hi, thanks, that was exactly what I needed.
last question on this matter, just to be sure, if I set e.Handled = true , the 'normal' mouse click will not occur (MouseLeftButtonDown) , right?
I am assuming that by the "first request" on this matter, you are referring to the action of clicking on a series data point and displaying its values. Please correct me if this impression is incorrect, as the following goes off of it.
If my above impression is correct, I would recommend utilizing the XamDataChart's SeriesMouseLeftButtonDown event for this. This event will fire on click of a point in a particular series in the chart, and the event arguments of this event can net you the series (e.Series), XamDataChart (e.Chart), and underlying data item to that point (e.Item) of the point that you clicked on. You can then display the information related to that point by casting the data item to an instance of its type and extracting the property information from it.