Hi All,
Hope someone can help me. I've got a XamDataChart with multiple scatter line series lines. I want to select a certain datapoint on a series and move that point to the users selected position on the chart with my mouse. Is this possible?
Ive got this code so far to give me my mouse position when the user clicks(Mouse down event):
var x = Chart.Axes.OfType<NumericXAxis>().First(); var y = Chart.Axes.OfType<NumericYAxis>().First(); var viewport = new Rect(0, 0, x.ActualWidth, y.ActualHeight); var window = gearShiftProfileChart.WindowRect;
var position = e.GetPosition(Chart);
var unscaledX = x.GetUnscaledValue(position.X, window, viewport); var unscaledY = y.GetUnscaledValue(position.Y, window, viewport);
System.Windows.MessageBox.Show("x: " + unscaledX + ", y:" + unscaledY);
Friendly regards
Roelof
Hello Roelof,
There are a few ways to achieve your requirement.
1. I recommend handling the following events on the DataChart
a. SeriesMouseLeftButtonDownb. PreviewMouseMovec. PreviewMouseUp
You were on the right path. You may reposition the data points via the chart's GetUnscaledValue method to change the x and y positions.
eg.
private void XChart_SeriesMouseLeftButtonDown(object sender, DataChartMouseButtonEventArgs e) { this.DraggingWidget = e.Item as Widget; }
private void XChart_PreviewMouseMove(object sender, MouseEventArgs e) { if (this.DraggingWidget != null) { Point p = e.GetPosition(xChart);
this.DraggingWidget.ValueX = this.xChart.Axes.OfType<NumericXAxis>().First().GetUnscaledValue(p.X, this.xChart.WindowRect, this.xChart.ViewportRect); this.DraggingWidget.ValueY = this.xChart.Axes.OfType<NumericYAxis>().First().GetUnscaledValue(p.Y, this.xChart.WindowRect, this.xChart.ViewportRect); } }
private void XChart_PreviewMouseUp(object sender, MouseButtonEventArgs e) { this.DraggingWidget = null; }
I've attached a complete sample demonstrating this.
2. You may also find the following forum post useful, since it demonstrates using a behavior.
https://ko.infragistics.com/community/forums/t/81022.aspx
Let me know if you have any questions.
Hi Michael,
Thanks for the speedy reply. I am targeting Dot net 4.0 as ive got clients running windows XP still :-/
I see that the Method private void RaisePropertyChanged([CallerMemberName] string propertyName = "NONE")
does not seem to work. CallerMemberName does not pick up.
Could you please assist.
Friendly Regards,
The necessary change must be done to the NotifyPropertyChanged method. Simply passing in a string will work for the properties.
For more details please visit msdn: https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.100).aspx
public class Widget : INotifyPropertyChanged { private double _ValueX; public double ValueX { get { return this._ValueX; } set { bool changed = this.ValueX != value; if (changed) { this._ValueX = value; NotifyPropertyChanged("ValueX"); } } } private double _ValueY; public double ValueY { get { return this._ValueY; } set { bool changed = this.ValueY != value; if (changed) { this._ValueY = value; NotifyPropertyChanged("ValueY"); } } } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } }
public class Widget : INotifyPropertyChanged { private double _ValueX; public double ValueX { get { return this._ValueX; } set { bool changed = this.ValueX != value; if (changed) { this._ValueX = value; NotifyPropertyChanged("ValueX"); } } } private double _ValueY; public double ValueY { get { return this._ValueY; } set { bool changed = this.ValueY != value; if (changed) { this._ValueY = value; NotifyPropertyChanged("ValueY"); } } } public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } }
Thanks for the help. I got it to work, Just one more thing that I picked up. when i click on a point my mouse cursor is on the point. As soon is i move my mouse the point jumps away from under my mouse cursor. Is there a reason for this.
Thank you for following up. The jumping is a result of allowing the axes to have an unrestricted min and max value. If you set the Min and Max properties on the Axes then you won't experience this behavior.
NumericXAxis xAxis = new NumericXAxis { MinimumValue = 0, MaximumValue = 4 }; NumericYAxis yAxis = new NumericYAxis { MinimumValue = 0, MaximumValue = 4 };
With this one I am struggling. I've added the ranges but it still jumps.
Could you please attach an example?
Please see attached below, and clarify whether or not you experience any issues. Please keep in mind that dragging data points is considered to be a new product idea.
You can suggest new product ideas for future versions by emailing ideas@infragistics.com.
Submitting your idea will send it directly to our product management team so that it can be imported into our new ideas community once live: http://ideas.infragistics.com
Remember when submitting your idea to explain the context in which a feature would be used and why it is needed as well as anything that would prevent you from accomplishing this today. You can even add screenshots to build a stronger case. You can also link back to this thread for additional details.Thank you in advance to submitting your product idea.
Yes, I was just about to suggest it! You can also subtract .30 at the very end of the GetUnscaledValue method.
Glad you were able to address it. Have a nice day.
Resolved this issue by adjusting this line(Added -30 to the p.X value)
this.DraggingWidget.ValueX = this.xChart.Axes.OfType<NumericXAxis>().First().GetUnscaledValue(p.X - 30, this.xChart.WindowRect, this.xChart.ViewportRect);
The point still jumps to the right hand side of the cursor as soon as I move my mouse. Not end of the world...
Thanks for the help
Regards,