Hello everyone,
is it possible to edit interactively the XamDataChart points with the mouse, e.g. set new point with the mouse click or drag the existing one?
Any help will be greatly appreciated.
Roelof,
Your question was answered in the Moving series data point with mouse thread that you created for this.
Hi Guys,
Is there a way to move the existing data points to a new position?
Friendly Regards,
Roelof
Hello Kabsau,
try please this example
Bonizt
Dear bonitz, I could not repeat your example. I understand the idea of work, but I had not achieved the result. Please laid out his example in the project (as Stefan Stoyanov).
Hello kabsau,
Try foolowing code (modified Infragistics sample).
Add somewhere:
xamChart.PreviewMouseLeftButtonDown += OnPreviewMouseLeftButtonDown;
void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // Assumed there is only one serie. var series = this.xamChart.Series.FirstOrDefault(); if (series == null) return; var point = e.GetPosition(series); if (series.Chart.Axes.OfType<NumericXAxis>().Any()) { double unscaledX; double unscaledY; UnscalePoint(series, point, out unscaledX, out unscaledY); var data = xamChart.DataContext as ObservableCollection<LiveViewDataPoint>; // Get insertion index. int index = 0; foreach (var dataPoint in data) { if (dataPoint.X < unscaledX) { index++; continue; } if (dataPoint.X == unscaledX) { // Don't insert points with the same X-coordinate. index = -1; } break; } var newPoint = new LiveViewDataPoint() {X = (int) unscaledX, Y = unscaledY}; if (index == data.Count()) { // Add point at the end of the curve. data.Add(newPoint); } else if (index != -1) { // Insert new point. data.Insert(index, newPoint); } } }
public class LiveViewDataPoint { public double X { get; set; } public double Y { get; set; } }private static void UnscalePoint(Series series, Point point, out double unscaledX, out double unscaledY) { var xAxis = series.Chart.Axes.OfType<NumericXAxis>().First(); var yAxis = series.Chart.Axes.OfType<NumericYAxis>().First(); var viewport = new Rect(0, 0, xAxis.ActualWidth, yAxis.ActualHeight); var window = series.Chart.WindowRect; unscaledX = xAxis.GetUnscaledValue(point.X, window, viewport); unscaledY = yAxis.GetUnscaledValue(point.Y, window, viewport); }