SciChart iOS v2.x API > Axis APIs > Axis Ranging - How to Listen to VisibleRange Changes
Axis Ranging - How to Listen to VisibleRange Changes

How to Listen to VisibleRange Changes

It is possible to subscribe to VisibleRange Changes using a SCIAxisVisibleRangeChanged callback:

// Register a VisibleRangeChanged callback
SCICallbackHelper * helper = [axis registerVisibleRangeChangedCallback:
               ^(id<SCIRangeProtocol> newRange, id<SCIRangeProtocol> oldRange, BOOL isAnimated, id sender) {
                   // TODO: Do something on range change
                   // isAnimated will be TRUE if the current operation is an animated zoom or pan
               }];

// When finished, unsubscribe to the callback
[helper remove];
// Register a VisibleRangeChanged callback
var helper: SCICallbackHelper? = axis.registerVisibleRangeChangedCallback({(_ newRange: SCIRangeProtocol, _ oldRange: SCIRangeProtocol, _ isAnimated: Bool, _ sender: Any) -> Void in
        // TODO: Do something on range change
        // isAnimated will be TRUE if the current operation is an animated zoom or pan
    }) 

// When finished, unsubscribe to the callback
helper?.remove()
// Register a VisibleRangeChanged callback
var helper = axis.RegisterVisibleRangeChangedCallback((newRange, oldRange, isAnimated, sender) =>
{
    // TODO: Do something on range change
    // isAnimated will be TRUE if the current operation is an animated zoom or pan               
});
helper.Remove();
helper.Dispose();

The most typical use for this callback is to perform some kind of operation when the Axis.VisibleRange changes, such as updating UI.

It is also possible to use this callback to restrict the VisibleRange in some way, e.g set a bounded or clipped range onto Axis.VisibleRange when the range changes outside of a desired area.

Note that you can differentiate between changes that were part of an animation by checking the isAnimated parameter.

For example, an animated zoom to extents operation will fire the callback many times with isAnimated = true, then once at the end with isAnimated = false.

See Also