Chart for .NET / User's Guide / Axes / Value Snapping

In This Topic
    Value Snapping
    In This Topic

    Several objects in the chart object model have the ability to snap to certain values on the scales / axes they are displayed on. These objects include the NRangeSelection, NAxisCursor and NIndicator derived classes.

    The value snapping functionality is controlled through an instance of an object deriving from the abstract NValueSnapper class. The following table shows the possible value snapper objects and how they snap values to a chart or gauge axis:

    Class Description
    NAxisMajorTickSnapper Snaps values to the major ticks of the axis
    NAxisMinorTickSnapper Snaps values to the minor ticks of the axis
    NAxisRulerClampSnapper Clamps values to the axis min / max values
    NAxisRulerMinMaxSnapper Snaps values to the axis min / max values
    NNumericValueSnapper Represents a value snapper that snaps values to the nearest step from a specified origin.
    NDateTimeValueSnapper Represents a value snapper that snaps date/time values to the nearest date time step from a specified date/time origin.

    The following code shows how to implement a radial gauge with a needle indicator snapping to the nearest value with step 5 – for example 0, 5, 10 etc.

    C#
    Copy Code
    NRadialGaugePanel radialGauge = new NRadialGaugePanel();
    
    NNeedleValueIndicator needleIndicator = new NNeedleValueIndicator();
    needleIndicator.ValueSnapper = new NNumericValueSnapper(5);
    radialGauge.Indicators.Add(needleIndicator);
    
    nChartControl1.Panels.Clear();
    nChartControl1.Panels.Add(radialGauge);
    
    nChartControl1.Controller.Tools.Clear();
    nChartControl1.Controller.Tools.Add(new NSelectorTool());
    nChartControl1.Controller.Tools.Add(new NIndicatorDragTool()); 
    
    Visual Basic
    Copy Code
    Dim radialGauge As New NRadialGaugePanel
    
    Dim needleIndicator As New NNeedleValueIndicator
    needleIndicator.ValueSnapper = New NNumericValueSnapper(5)
    radialGauge.Indicators.Add(needleIndicator)
    
    NChartControl1.Panels.Clear()
    NChartControl1.Panels.Add(radialGauge)
    
    NChartControl1.Controller.Tools.Clear()
    NChartControl1.Controller.Tools.Add(New NSelectorTool)
    NChartControl1.Controller.Tools.Add(New NIndicatorDragTool)
    
     Related Examples

    Windows Forms: Gauge Gallery \ Gauges \ Interactivity \Dragging Indicators

    Windows Forms: Interactivity \ Tools \ Data Cursor Tool

    See Also