SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
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.
Demonstrates the speed and power of SciChart’s iOS Charts in a real-time. The high-performance is very important for charts used in Trading, Medical and Scientific applications and others. This example showcases loading or startup time of SciChart by appending 20 K points to a Scatter Chart and rendering in realtime. This can be done using SCIXyScatterRenderableSeries and
SCIXyDataSeries.
The Swift and Objective-C source code for the iOS and macOS Scatter Performance Demo (20k points) 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).
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2018. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// ScatterSpeedTestSciChart.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 ScatterSpeedTestSciChart: SingleChartLayout {
let PointsCount: Int32 = 20000
var _timer: Timer!
let _scatterDataSeries = SCIXyDataSeries(xType: .double, yType: .double)
override func initExample() {
let xAxis = SCINumericAxis()
xAxis.autoRange = .always
let yAxis = SCINumericAxis()
yAxis.autoRange = .always
let doubleSeries = BrownianMotionGenerator.getRandomData(withMin: -50, max: 50, count: PointsCount)
_scatterDataSeries.acceptUnsortedData = true
_scatterDataSeries.appendRangeX(doubleSeries!.xValues, y: doubleSeries!.yValues, count: doubleSeries!.size)
let marker = SCICoreGraphicsPointMarker()
marker.width = 6
marker.height = 6
let rSeries = SCIXyScatterRenderableSeries()
rSeries.dataSeries = _scatterDataSeries
rSeries.pointMarker = marker
SCIUpdateSuspender.usingWithSuspendable(surface) {
self.surface.xAxes.add(xAxis)
self.surface.yAxes.add(yAxis)
self.surface.renderableSeries.add(rSeries)
}
_timer = Timer.scheduledTimer(timeInterval: 0.002, target: self, selector: #selector(updateData), userInfo: nil, repeats: true)
}
@objc fileprivate func updateData(_ timer: Timer) {
for i in 0..<_scatterDataSeries.count() {
let x = _scatterDataSeries.xValues().value(at: i)
let y = _scatterDataSeries.yValues().value(at: i)
_scatterDataSeries.update(at: i, x: SCIGeneric(SCIGenericDouble(x) + randf(-1.0, 1.0)), y: SCIGeneric(SCIGenericDouble(y) + randf(-0.5, 0.5)))
}
}
override func willMove(toWindow newWindow: UIWindow?) {
super.willMove(toWindow: newWindow)
if (newWindow == nil) {
_timer.invalidate()
_timer = nil
}
}
}