Chart for .NET / User's Guide / Interactivity / Axis Scroll Tool

In This Topic
    Axis Scroll Tool
    In This Topic

    The axis scroll tool passes mouse and keyboard events to the scrollbars of the axis when they are enabled. It can work closely with the NDataPanTool and NDataZoomTool tools to produce highly interactive charts.

    The following code will create an XY Scatter Point chart that enable the user to zoom in/out,scroll and pan it's data:

    C#
    Copy Code
    NChart chart = chartControl.Charts[0];
    
    // create the point series
    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));
    }
    
    // configure the axes
    NLinearScaleConfigurator linearScale = new NLinearScaleConfigurator();
    chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = linearScale;
    chart.Axis(StandardAxis.PrimaryX).ScrollBar.ResetButton.Visible = false;
    
    NNumericAxisPagingView numericPagingView = new NNumericAxisPagingView(new NRange1DD(0, 20));
    chart.Axis(StandardAxis.PrimaryX).PagingView = numericPagingView;
    
    numericPagingView = new NNumericAxisPagingView(new NRange1DD(0, 20));
    chart.Axis(StandardAxis.PrimaryY).PagingView = numericPagingView;
    chart.Axis(StandardAxis.PrimaryY).ScrollBar.ResetButton.Visible = false;
    chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = true;
    chart.Axis(StandardAxis.PrimaryY).ScrollBar.Visible = true;
    chartControl.Controller.Tools.Add(new NAxisScrollTool());
    
    // add range selection (needed for zoom in)
    chart.RangeSelections.Add(new NRangeSelection());
    
    // configure the tools collection
    chartControl.Controller.Tools.Add(new NSelectorTool());
    chartControl.Controller.Tools.Add(new NAxisScrollTool());
    chartControl.Controller.Tools.Add(new NDataZoomTool());
    chartControl.Controller.Tools.Add(new NDataPanTool());
    chartControl.Refresh();
    
    Visual Basic
    Copy Code
    Dim chart As NCartesianChart = chartControl.Charts(0)
    
    ' create the point series
    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
    
    ' configure the axes
    Dim linearScale As NLinearScaleConfigurator = New NLinearScaleConfigurator
    chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = linearScale
    chart.Axis(StandardAxis.PrimaryX).ScrollBar.ResetButton.Visible = False
    
    Dim numericPagingView As NNumericAxisPagingView = New NNumericAxisPagingView(New NRange1DD(0, 20))
    chart.Axis(StandardAxis.PrimaryX).PagingView = numericPagingView
    
    numericPagingView = New NNumericAxisPagingView(New NRange1DD(0, 20))
    chart.Axis(StandardAxis.PrimaryY).PagingView = numericPagingView
    chart.Axis(StandardAxis.PrimaryY).ScrollBar.ResetButton.Visible = False
    
    chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = True
    chart.Axis(StandardAxis.PrimaryY).ScrollBar.Visible = True
    chartControl.Controller.Tools.Add(New NAxisScrollTool)
    
    ' add range selection (needed for zoom in)
    chart.RangeSelections.Add(New NRangeSelection)
    
    ' configure the tools collection
    chartControl.Controller.Tools.Add(New NSelectorTool)
    chartControl.Controller.Tools.Add(New NAxisScrollTool)
    chartControl.Controller.Tools.Add(New NDataZoomTool)
    chartControl.Controller.Tools.Add(New NDataPanTool)
    chartControl.Refresh()
    
    See Also