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.
This example demonstrates how to implement interactive pan and zoom functionality in a SciChart chart, allowing users to easily explore data. By enabling both panning and zooming gestures, users can drag the chart to pan across the data and pinch to zoom in or out.
SciChart’s built-in Chart Modifiers provide a smooth and responsive user experience for visualizing large datasets. The example shows how to configure the chart to support these gestures, providing an intuitive way to explore data in both dimensions.
The Swift and Objective-C source code for the iOS and macOS Pan and Zoom a Chart 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).
PanAndZoomChartView.swift
View source code//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// PanAndZoomChartView.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 PanAndZoomChartView: SCDPanAndZoomChartViewControllerBase {
override var associatedType: AnyClass { return SCIChartSurface.self }
override func initExample() {
let xAxis = SCINumericAxis()
xAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
xAxis.visibleRange = SCIDoubleRange(min: 3, max: 6)
let yAxis = SCINumericAxis()
yAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
let ds1 = SCIXyDataSeries(xType: .double, yType: .double)
let ds2 = SCIXyDataSeries(xType: .double, yType: .double)
let ds3 = SCIXyDataSeries(xType: .double, yType: .double)
let data1 = SCDDataManager.getDampedSinewave(withPad: 300, amplitude: 1.0, phase: 0.0, dampingFactor: 0.01, pointCount: 1000, freq: 10)
let data2 = SCDDataManager.getDampedSinewave(withPad: 300, amplitude: 1.0, phase: 0.0, dampingFactor: 0.024, pointCount: 1000, freq: 10)
let data3 = SCDDataManager.getDampedSinewave(withPad: 300, amplitude: 1.0, phase: 0.0, dampingFactor: 0.049, pointCount: 1000, freq: 10)
ds1.append(x: data1.xValues, y: data1.yValues)
ds2.append(x: data2.xValues, y: data2.yValues)
ds3.append(x: data3.xValues, y: data3.yValues)
zoomPanModifier = SCIZoomPanModifier()
SCIUpdateSuspender.usingWith(surface) {
self.surface.xAxes.add(xAxis)
self.surface.yAxes.add(yAxis)
self.surface.renderableSeries.add(self.getRenderableSeriesWith(ds1, brushColor: 0x77b4efdb, strokeColor: 0xFF68bcae))
self.surface.renderableSeries.add(self.getRenderableSeriesWith(ds2, brushColor: 0x77efb4d3, strokeColor: 0xFFae418d))
self.surface.renderableSeries.add(self.getRenderableSeriesWith(ds3, brushColor: 0x77b4bfed, strokeColor: 0xFF274b92))
self.surface.chartModifiers.add(items: SCIPinchZoomModifier(), self.zoomPanModifier, SCIZoomExtentsModifier())
}
}
fileprivate func getRenderableSeriesWith(_ dataSeries: SCIXyDataSeries, brushColor: UInt32, strokeColor: UInt32) -> SCIFastMountainRenderableSeries {
let rSeries = SCIFastMountainRenderableSeries()
rSeries.strokeStyle = SCISolidPenStyle(color: strokeColor, thickness: 1)
rSeries.areaStyle = SCISolidBrushStyle(color: brushColor)
rSeries.dataSeries = dataSeries
SCIAnimations.wave(rSeries, duration: 3.0, andEasingFunction: SCICubicEase())
return rSeries
}
}
Back to iOS & macOS charts Examples


