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.
With the high-performance demanding applications in mind SciChart allows realtime plotting of millions of datapoints. We have created a selection of example to demonstrate how to render different charts in realtime. This example showcases the 3D Realtime iOS Point-Cloud example, it updates a SCIXyzDataSeries3D DataSeries in real-time to render a SCIScatterRenderableSeries3D renderable series.
Read more in SciChart 3D iOS Tutorials and Documentation:
The Swift and Objective-C source code for the iOS and macOS RealTime Point-Cloud 3D 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).
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// RealtimePointCloud3DChartView.m 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.
//******************************************************************************
#import "RealtimePointCloud3DChartView.h"
#import "SCDRandomUtil.h"
#import "SCDDataManager.h"
@implementation RealtimePointCloud3DChartView {
NSTimer *_timer;
SCIXyzDataSeries3D *_dataSeries;
SCIDoubleValues *_xData;
SCIDoubleValues *_yData;
SCIDoubleValues *_zData;
}
- (Class)associatedType { return SCIChartSurface3D.class; }
- (void)initExample {
_xData = [SCIDoubleValues new];
_yData = [SCIDoubleValues new];
_zData = [SCIDoubleValues new];
SCINumericAxis3D *xAxis = [SCINumericAxis3D new];
xAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.1 max:0.1];
xAxis.autoRange = SCIAutoRange_Once;
SCINumericAxis3D *yAxis = [SCINumericAxis3D new];
yAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.1 max:0.1];
yAxis.autoRange = SCIAutoRange_Once;
SCINumericAxis3D *zAxis = [SCINumericAxis3D new];
zAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.1 max:0.1];
zAxis.autoRange = SCIAutoRange_Once;
SCIEllipsePointMarker3D *pointMarker = [SCIEllipsePointMarker3D new];
pointMarker.fillColor = 0x77ADFF2F;
pointMarker.size = 3.f;
for (int i = 0; i < 1000; ++i) {
double x = [SCDDataManager getGaussianRandomNumber:5 stdDev:1.5];
double y = [SCDDataManager getGaussianRandomNumber:5 stdDev:1.5];
double z = [SCDDataManager getGaussianRandomNumber:5 stdDev:1.5];
[_xData add:x];
[_yData add:y];
[_zData add:z];
}
_dataSeries = [[SCIXyzDataSeries3D alloc] initWithXType:SCIDataType_Double yType:SCIDataType_Double zType:SCIDataType_Double];
[_dataSeries appendXValues:_xData yValues:_yData zValues:_zData];
SCIScatterRenderableSeries3D *rSeries = [SCIScatterRenderableSeries3D new];
rSeries.dataSeries = _dataSeries;
rSeries.pointMarker = pointMarker;
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
self.surface.xAxis = xAxis;
self.surface.yAxis = yAxis;
self.surface.zAxis = zAxis;
[self.surface.renderableSeries add:rSeries];
[self.surface.chartModifiers add:[SCDExampleBaseViewController createDefaultModifiers3D]];
}];
_timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(updateData) userInfo:nil repeats:YES];
}
- (void)updateData {
double *xItems = _xData.itemsArray;
double *yItems = _yData.itemsArray;
double *zItems = _zData.itemsArray;
for (int i = 0; i < _dataSeries.count; i++) {
xItems[i] += SCDRandomUtil.nextDouble - 0.5;
yItems[i] += SCDRandomUtil.nextDouble - 0.5;
zItems[i] += SCDRandomUtil.nextDouble - 0.5;
}
[_dataSeries updateXValues:_xData yValues:_yData zValues:_zData at:0];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[_timer invalidate];
_timer = nil;
}
@end
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// RealtimePointCloud3DChartView.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 RealtimePointCloud3DChartView: SCDSingleChartViewController<SCIChartSurface3D> {
override var associatedType: AnyClass { return SCIChartSurface3D.self }
private let dataSeries = SCIXyzDataSeries3D(xType: .double, yType: .double, zType: .double)
private let xData = SCIDoubleValues()
private let yData = SCIDoubleValues()
private let zData = SCIDoubleValues()
private var timer: Timer!
override func initExample() {
let xAxis = SCINumericAxis3D()
xAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
xAxis.autoRange = .once
let yAxis = SCINumericAxis3D()
yAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
yAxis.autoRange = .once
let zAxis = SCINumericAxis3D()
zAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
zAxis.autoRange = .once
let pointMarker3D = SCIEllipsePointMarker3D()
pointMarker3D.fillColor = 0x77ADFF2F
pointMarker3D.size = 3.0
for _ in 0 ..< 1000 {
let x = SCDDataManager.getGaussianRandomNumber(5, stdDev: 1.5)
let y = SCDDataManager.getGaussianRandomNumber(5, stdDev: 1.5)
let z = SCDDataManager.getGaussianRandomNumber(5, stdDev: 1.5)
xData.add(x)
yData.add(y)
zData.add(z)
}
dataSeries.append(x: xData, y: yData, z: zData)
let rSeries = SCIScatterRenderableSeries3D()
rSeries.dataSeries = dataSeries
rSeries.pointMarker = pointMarker3D
SCIUpdateSuspender.usingWith(surface) {
self.surface.xAxis = xAxis
self.surface.yAxis = yAxis
self.surface.zAxis = zAxis
self.surface.renderableSeries.add(rSeries)
self.surface.chartModifiers.add(SCDExampleBaseViewController.createDefaultModifiers3D())
}
timer = Timer.scheduledTimer(timeInterval: 0.02, target: self, selector: #selector(updateData), userInfo: nil, repeats: true)
}
@objc fileprivate func updateData(_ timer: Timer) {
for i in 0 ..< dataSeries.count {
xData.set(xData.getValueAt(i) + SCDRandomUtil.nextDouble() - 0.5 , at: i)
yData.set(yData.getValueAt(i) + SCDRandomUtil.nextDouble() - 0.5 , at: i)
zData.set(zData.getValueAt(i) + SCDRandomUtil.nextDouble() - 0.5 , at: i)
}
dataSeries.update(x: xData, y: yData, z: zData, at: 0)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
timer.invalidate()
timer = nil
}
}