Android & Xamarin.Android Charting Documentation - SciChart Android Charts SDK v2.x
Tutorial 04 - Adding Zooming, Panning Behavior

Following on from Tutorial 04 - Adding Series to a Chart where we created some series, we will now add zooming, panning behaviors to the chart.

Adding Zooming, Panning Behaviors

So far in the tutorial series, we have created a new chart, added an XAxis, YAxis, some series and also some simple zoom modifiers. We are going to extend this now and add some more interaction behaviors.

Adding ChartModifiers to a SciChartSurface

In SciChart, all chart interactions are defined by ChartModifiers. Besides several modifiers provided out of the box, it is possible to write custom modifiers or extends the existing ones. The provided modifiers include PinchZoomModifierRubberBandXyZoomModifierZoomPanModifierZoomExtentsModifier CursorModifierRolloverModifier, SeriesSelectionModifier and others.

Now we are going to create and configure a couple of new modifiers using SciChartBuilder and add them to the ChartModifiers collection of the SciChartSurface:

Copy Code
// Add a bunch of interaction modifiers to a ModifierGroup
ModifierGroup additionalModifiers = sciChartBuilder.newModifierGroup()

        .withPinchZoomModifier().build()

        .withZoomPanModifier().withReceiveHandledEvents(true).build()

        .withZoomExtentsModifier().withReceiveHandledEvents(true).build()

        .withXAxisDragModifier().withReceiveHandledEvents(true).withDragMode(AxisDragModifierBase.AxisDragMode.Scale).withClipModex(ClipMode.None).build()

        .withYAxisDragModifier().withReceiveHandledEvents(true).withDragMode(AxisDragModifierBase.AxisDragMode.Pan).build()

        .build();

// Add the modifiers to the SciChartSurface
surface.getChartModifiers().add(additionalModifiers);

After re-building and running the application the chart should behave like this:

 

Further Reading

To learn more about the zooming and panning modifiers provided by SciChart out of the box please find links to the corresponding documentation articles below:

Also you can find out about the ChartModifiers API and how to use it to create custom chart modifiers in the Custom Modifiers - ChartModifierBase API article.

See Also

Quickstart Guide