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.
When creating SciChart Component we have demanding high performance realtime iOS applications in mind. There is a number of examples featuring how to plot graphs in iOS in realtime.
This example demonstrates how to update SCIUniformGridDataSeries3D in realtime to render an iOS 3D SCISurfaceMeshRenderableSeries3D.
Read more in SciChart iOS Swift and Objective-C Tutorials:
The Swift and Objective-C source code for the iOS and macOS RealTime 3D Surface Mesh 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
//
// RealtimeUniformMesh3DChartView.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 "RealtimeUniformMesh3DChartView.h"
@interface RealtimeUniformMesh3DChartView ()
@property (strong, nonatomic) NSTimer *timer;
@property (strong, nonatomic) SCIUniformGridDataSeries3D *dataSeries;
@property (strong, nonatomic) SCIDoubleValues *buffer;
@property (nonatomic) int w;
@property (nonatomic) int h;
@property (nonatomic) int frames;
@end
@implementation RealtimeUniformMesh3DChartView
- (Class)associatedType { return SCIChartSurface3D.class; }
- (void)initExample {
_buffer = [SCIDoubleValues new];
_w = 50;
_h = 50;
_frames = 0;
SCINumericAxis3D *xAxis = [SCINumericAxis3D new];
xAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.1 max:0.1];
xAxis.autoRange = SCIAutoRange_Always;
SCINumericAxis3D *yAxis = [SCINumericAxis3D new];
yAxis.visibleRange = [[SCIDoubleRange alloc] initWithMin:0.0 max:1.0];
SCINumericAxis3D *zAxis = [SCINumericAxis3D new];
zAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.1 max:0.1];
zAxis.autoRange = SCIAutoRange_Always;
_dataSeries = [[SCIUniformGridDataSeries3D alloc] initWithXType:SCIDataType_Double yType:SCIDataType_Double zType:SCIDataType_Double xSize:_w zSize:_h];
unsigned int colors[7] = { 0xFF1D2C6B, 0xFF0000FF, 0xFF00FFFF, 0xFFADFF2F, 0xFFFFFF00, 0xFFFF0000, 0xFF8B0000 };
float stops[7] = { 0, 0.1, 0.3, 0.5, 0.7, 0.9, 1 };
SCIGradientColorPalette *palette = [[SCIGradientColorPalette alloc] initWithColors:colors stops:stops count:7];
SCISurfaceMeshRenderableSeries3D *rSeries = [SCISurfaceMeshRenderableSeries3D new];
rSeries.dataSeries = _dataSeries;
rSeries.stroke = 0x7FFFFFFF;
rSeries.strokeThickness = 2.0;
rSeries.drawSkirt = NO;
rSeries.minimum = 0;
rSeries.maximum = 0.5;
rSeries.shininess = 64;
rSeries.meshColorPalette = palette;
[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.033 target:self selector:@selector(updateData) userInfo:nil repeats:YES];
}
- (void)updateData {
__weak typeof(self) wSelf = self;
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
wSelf.frames += 1;
double wc = wSelf.w * 0.5;
double hc = wSelf.h * 0.5;
double freq = sin(wSelf.frames * 0.1) * 0.1 + 0.1;
SCIIndexCalculator *indexCalculator = wSelf.dataSeries.indexCalculator;
wSelf.buffer.count = indexCalculator.size;
double *bufferItems = wSelf.buffer.itemsArray;
for (int i = 0; i < wSelf.h; ++i) {
for (int j = 0; j < wSelf.w; ++j) {
double x = (wc - i) * (wc - i) + (hc - j) * (hc - j);
double radius = sqrt(x);
double d = M_PI * radius * freq;
double value = sin(d) / d;
NSInteger index = [indexCalculator getIndexAtUIndex:i andVIndex:j];
bufferItems[index] = isnan(value) ? 1 : value;
}
}
[wSelf.dataSeries copyFromValues:wSelf.buffer];
}];
}
- (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
//
// RealtimeUniformMesh3DChartView.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 RealtimeUniformMesh3DChartView: SCDSingleChartViewController<SCIChartSurface3D> {
override var associatedType: AnyClass { return SCIChartSurface3D.self }
private let w = 50
private let h = 50
private var frames = 0;
private var timer: Timer!
private var dataSeries: SCIUniformGridDataSeries3D!
private let buffer = SCIDoubleValues()
override func initExample() {
let xAxis = SCINumericAxis3D()
xAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
xAxis.autoRange = .always
let yAxis = SCINumericAxis3D()
yAxis.visibleRange = SCIDoubleRange(min: 0, max: 1.0)
let zAxis = SCINumericAxis3D()
zAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
zAxis.autoRange = .always
dataSeries = SCIUniformGridDataSeries3D(xType: .double, yType: .double, zType: .double, xSize: w, zSize: h)
let colors: [UInt32] = [0xFF1D2C6B, 0xFF0000FF, 0xFF00FFFF, 0xFFADFF2F, 0xFFFFFF00, 0xFFFF0000, 0xFF8B0000]
let stops: [Float] = [0, 0.1, 0.3, 0.5, 0.7, 0.9, 1]
let palette = SCIGradientColorPalette(colors: colors, stops: stops, count: 7)
let rSeries = SCISurfaceMeshRenderableSeries3D()
rSeries.dataSeries = dataSeries
rSeries.stroke = 0x7FFFFFFF
rSeries.strokeThickness = 2.0
rSeries.drawSkirt = false
rSeries.minimum = 0
rSeries.maximum = 0.5
rSeries.shininess = 64
rSeries.meshColorPalette = palette
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.033, target: self, selector: #selector(updateData), userInfo: nil, repeats: true)
}
@objc fileprivate func updateData(_ timer: Timer) {
SCIUpdateSuspender.usingWith(surface) {
self.frames += 1
let wc = Double(self.w) * 0.5
let hc = Double(self.h) * 0.5
let freq = sin(Double(self.frames) * 0.1) * 0.1 + 0.1
let indexCalculator = self.dataSeries.indexCalculator!
self.buffer.count = indexCalculator.size
for i in 0 ..< self.h {
for j in 0 ..< self.w {
let x = Double((wc - Double(i)) * (wc - Double(i))) + Double((hc - Double(j))*(hc - Double(j)))
let radius = sqrt(x)
let d = Double.pi * radius * freq
let value = sin(d) / d
let index = indexCalculator.getIndex(atU: i, v: j)
self.buffer.set(value.isNaN ? 1 : value, at: index)
}
}
self.dataSeries.copy(from: self.buffer)
}
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
timer.invalidate()
timer = nil
}
}