Chart for .NET / User's Guide / Interactivity / Drag Tools / Data Point Drag Tool

In This Topic
    Data Point Drag Tool
    In This Topic

    The data point dragging feature of the control is represented by the NDataPointDragTool class. When an object of this type is present in the Tools collection it will work with the current Selection to enable data point dragging.

    To illustrate this lets take a look at the following code showing how to create a XY scatter point chart and enable the data point dragging feature allowing the user to move data points with the mouse:

    C#
    Copy Code
    NChart chart = chartControl.Charts[0];
    NLinearScaleConfigurator linearConfigurator = new NLinearScaleConfigurator();
    chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = linearConfigurator;
    
    NPointSeries point = (NPointSeries)chart.Series.Add(SeriesType.Point);
    point.UseXValues = true;
    
    Random random = new Random();
    
    for (int i = 0; i < 10; i++)
    {
        point.Values.Add(random.Next(100));
        point.XValues.Add(random.Next(100));
    }
    
    chartControl.Controller.Tools.Add(new NSelectorTool());
    chartControl.Controller.Tools.Add(new NDataPointDragTool());
    chartControl.Refresh();
    
    Visual Basic
    Copy Code
    Dim chart As NChart = chartControl.Charts(0)
    Dim linearConfigurator As NLinearScaleConfigurator = New NLinearScaleConfigurator
    chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = linearConfigurator
    
    Dim point As NPointSeries = chart.Series.Add(SeriesType.Point)
    point.UseXValues = True
    
    Dim random As New Random
    
    For i As Integer = 0 To 9
        point.Values.Add(random.Next(100))
        point.XValues.Add(random.Next(100))
    Next i
    
    chartControl.Controller.Tools.Add(New NSelectorTool)
    chartControl.Controller.Tools.Add(New NDataPointDragTool)
    chartControl.Refresh()
    

    Now when the user presses the left mouse button over a data point and drags the mouse the data point X, Y values will change accordingly.

     Controlling Horizontal and Vertical Dragging

    There are cases when you may want to disable the dragging in the horizontal or vertical direction. You can easily achieve this by turning off the AllowHorizontalDragging or AllowVerticalDragging properties of the NDataPointDragTool. The following code disables dragging in the horizontal direction:

    C#
    Copy Code
    dataPointDragTool.AllowHorizontalDragging = false;
    
    Visual Basic
    Copy Code
    dataPointDragTool.AllowHorizontalDragging = False
    
     Modifying the Keyboard Shortcuts
    The NDataPointDragTool allows the user to change the data point value using the keyboard navigation keys. For example when the user selects a data point he/she can move it by pressing the Ctrl key plus any of the arrow keys. The shortcuts to move the data point Up, Down, Left and Right are controlled by the DragUpShortcut, DragDownShortcut, DragLeftShortcut, and DragRightShortcut respectively. You can also control the the horizontal and vertical step by touching the HorizontalStep and VerticalStep properties.
    See Also