Pre loader

iOS & macOS Drag Area to Zoom

iOS & macOS charts - Examples

Please note! These examples are new to SciChart iOS v4 release! SciChart’s OpenGL ES and Metal iOS and Metal macOS Chart library ships with hundred of Objective-C and Swift iOS & macOS Chart Examples which you can browse, play with and view the source-code. All of this is possible with the new and improved SciChart iOS Examples Suite and demo application for Mac, which ships as part of the SciChart SDK.

Download Examples

This example demonstrates how to implement a drag-to-zoom feature in SciChart, where users can zoom into specific areas of the chart by dragging within a designated “drag area.” This interactive feature is achieved by adding the `SCIRubberBandXyZoomModifier` chart modifier to the chart, allowing users to draw a rectangular region to zoom in on both the X and Y axes.

The `SCIRubberBandXyZoomModifier` automatically handles the zooming behavior, enabling a smooth and intuitive zooming experience by simply dragging within the chart.

The Swift and Objective-C source code for the iOS and macOS Drag Area to Zoom example is included below (Scroll down!).

Did you know that we have the source code for all our example available for free on Github?

Clone the SciChart.iOS.Examples from Github.

Also the SciChart iOS and Scichart macOS Trials contain the full source for the examples (link below).

DOWNLOAD THE IOS CHART EXAMPLES

DragAreaToZoomViewController.swift
View source code
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2020. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales:   sales@scichart.com
//
// DragAreaToZoomViewController.swift is part of the SCICHART® Examples. Permission is hereby granted
// to modify, create derivative works, distribute and publish any part of this source
// code whether for commercial, private or personal use.
//
// The SCICHART® examples are distributed in the hope that they will be useful, but
// without any warranty. It is provided "AS IS" without warranty of any kind, either
// expressed or implied.
//******************************************************************************

class DragAreaToZoomViewController: SCDDragAreaToZoomViewControllerBase {

    override func initExample() {
        let xAxis = SCINumericAxis()
        let yAxis = SCINumericAxis()
        yAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
        
        let data = SCDRandomWalkGenerator().setBias(0.0001).getRandomWalkSeries(10000)
        let dataSeries = SCIXyDataSeries(xType: .double, yType: .double)
        dataSeries.append(x: data.xValues, y: data.yValues)
        
        let rSeries = SCIFastLineRenderableSeries()
        rSeries.dataSeries = dataSeries
        rSeries.strokeStyle = SCISolidPenStyle(color: 0xFF68bcae, thickness: 1.0)
        
        rubberBand = SCIRubberBandXyZoomModifier()
        rubberBand.isXAxisOnly = isXAxisOnly
        rubberBand.isAnimated = useAnimation
        rubberBand.zoomExtentsY = zoomExtentsY
        
        SCIUpdateSuspender.usingWith(surface) {
            self.surface.xAxes.add(xAxis)
            self.surface.yAxes.add(yAxis)
            self.surface.renderableSeries.add(rSeries)
            self.surface.chartModifiers.add(items: SCIZoomExtentsModifier(), self.rubberBand)
            
            SCIAnimations.sweep(rSeries, duration: 3.0, easingFunction: SCICubicEase())
        }
    }
}
Back to iOS & macOS charts Examples