Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
255
Moving series data point with mouse
posted

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

Parents
  • 29105
    Verified Answer
    Offline posted

    Hello Roelof,

    There are a few ways to achieve your requirement.

    1. I recommend handling the following events on the DataChart

    a. SeriesMouseLeftButtonDown
    b. PreviewMouseMove
    c. 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://es.infragistics.com/community/forums/t/81022.aspx

    Let me know if you have any questions.

    WpfApplication1.zip
Reply Children