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.
Created in mind for the high-performance demanding applications SciChart features a variety of realtime charts. This example demonstrates how to update an iOS Waterfall 3D Chart in real-time.
Read more in SciChart iOS 3D Tutorials and Documentation:
The Swift and Objective-C source code for the iOS and macOS RealTime Waterfall 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
//
// RealtimeWaterfall3DChartView.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 "RealtimeWaterfall3DChartView.h"
#import "SCDDataManager.h"
const int PointsPerSlice = 128;
const int SliceCount = 10;
@interface RealtimeWaterfall3DChartView ()
@property (nonatomic) int tick;
@property (strong, nonatomic) NSTimer *timer;
@property (strong, nonatomic) NSArray<SCIDoubleValues *> *fftValues;
@property (strong, nonatomic) SCIWaterfallDataSeries3D *dataSeries;
@end
@implementation RealtimeWaterfall3DChartView
- (void)initExample {
_tick = 0;
_dataSeries = [[SCIWaterfallDataSeries3D alloc] initWithXType:SCIDataType_Double yType:SCIDataType_Double zType:SCIDataType_Double xSize:PointsPerSlice zSize:SliceCount];
_dataSeries.startX = @(10.0);
_dataSeries.stepX = @(1.0);
_dataSeries.startZ = @(25.0);
_dataSeries.startZ = @(10.0);
_fftValues = [SCDDataManager loadFFT];
[_dataSeries pushValuesRow:_fftValues[0]];
self.rSeries = [SCIWaterfallRenderableSeries3D new];
self.rSeries.dataSeries = _dataSeries;
self.rSeries.strokeThickness = 1.0;
[self setupColorPalettes];
[self setupPointMarker];
[self setupSliceThickness];
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
self.surface.xAxis = [SCINumericAxis3D new];
self.surface.yAxis = [SCINumericAxis3D new];
self.surface.zAxis = [SCINumericAxis3D new];
self.surface.zAxis.autoRange = SCIAutoRange_Always;
[self.surface.renderableSeries add:self.rSeries];
[self.surface.chartModifiers add:[SCDExampleBaseViewController createDefaultModifiers3D]];
[self.surface.camera.position assignX:-115 y:250 z:-570];
[self.surface.worldDimensions assignX:200 y:100 z:200];
}];
_timer = [NSTimer scheduledTimerWithTimeInterval:0.04 target:self selector:@selector(updateData) userInfo:nil repeats:YES];
}
- (void)updateData {
_tick += 1;
__weak typeof(self) wSelf = self;
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
int index = wSelf.tick % wSelf.fftValues.count;
[wSelf.dataSeries pushValuesRow:wSelf.fftValues[index]];
}];
}
- (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
//
// RealtimeWaterfall3DChartView.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 RealtimeWaterfall3DChartView: SCDWaterfall3DChartViewControllerBase {
override var associatedType: AnyClass { return SCIChartSurface3D.self }
private let PointsPerSlice = 128;
private let SliceCount = 10;
private let fftValues = SCDDataManager.loadFFT()
private let waterfallDataSeries = SCIWaterfallDataSeries3D(xType: .double, yType: .double, zType: .double, xSize: 128, zSize: 10)
private var tick = 0
private var timer: Timer!
override func initExample() {
waterfallDataSeries.set(startX: 10)
waterfallDataSeries.set(stepX: 1)
waterfallDataSeries.set(startZ: 25)
waterfallDataSeries.set(stepZ: 15)
waterfallDataSeries.push(fftValues[0])
rSeries = SCIWaterfallRenderableSeries3D()
rSeries.dataSeries = waterfallDataSeries
rSeries.strokeThickness = 1.0
setupColorPalettes()
setupPointMarker()
setupSliceThickness()
SCIUpdateSuspender.usingWith(surface) {
self.surface.xAxis = SCINumericAxis3D()
self.surface.yAxis = SCINumericAxis3D()
self.surface.zAxis = SCINumericAxis3D()
self.surface.zAxis.autoRange = .always
self.surface.renderableSeries.add(self.rSeries)
self.surface.chartModifiers.add(SCDExampleBaseViewController.createDefaultModifiers3D())
self.surface.camera.position.assignX(-115, y: 250, z: -570)
self.surface.worldDimensions.assignX(200, y: 100, z: 200)
}
timer = Timer.scheduledTimer(timeInterval: 0.04, target: self, selector: #selector(updateData), userInfo: nil, repeats: true)
}
@objc fileprivate func updateData(_ timer: Timer) {
self.tick += 1
SCIUpdateSuspender.usingWith(surface) {
let index = self.tick % self.fftValues.count
self.waterfallDataSeries.push(self.fftValues[index])
}
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
timer.invalidate()
timer = nil
}
}
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2020. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// SCDWaterfall3DChartViewControllerBase.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 "SCDWaterfall3DChartViewControllerBase.h"
#import "SCDSettingsPresenter.h"
#import "SCDToolbarButtonsGroup.h"
#import "SCDToolbarItem.h"
#import "SCDToolbarPopupItem.h"
#import "SCDLabeledSettingsItem.h"
#import "SCDSwitchItem.h"
#import "SCDConstants.h"
@implementation SCDWaterfall3DChartViewControllerBase {
SCDSettingsPresenter *_settingsPresenter;
NSArray<NSString *> *_strokeNames;
NSArray<NSString *> *_fillNames;
NSUInteger _currentStrokeColorPalette;
NSUInteger _currentFillColorPalette;
BOOL _showPointMarkers;
BOOL _isVolumetric;
SCIGradientColorPalette *_gradientFillColorPalette;
SCIGradientColorPalette *_gradientStrokeColorPalette;
SCISolidColorBrushPalette *_transparentColorPalette;
SCISolidColorBrushPalette *_solidStrokeColorPalette;
SCISolidColorBrushPalette *_solidFillColorPalette;
}
@synthesize rSeries = _rSeries;
- (Class)associatedType { return SCIChartSurface3D.class; }
- (void)commonInit {
_strokeNames = @[
@"Gradient Stroke Y",
@"Gradient Stroke Z",
@"Solid Fill Color (Green)",
@"None"
];
_fillNames = @[
@"Gradient Fill YAxis",
@"Gradient Fill ZAxis",
@"Solid Color Fill (Blue)",
@"None"
];
_currentStrokeColorPalette = 0; // by default YAxis
_currentFillColorPalette = 0; // by default YAxis
_showPointMarkers = NO;
_isVolumetric = YES;
unsigned int fillColors[5] = { 0xFFFF0000, 0xFFFFA500, 0xFFFFFF00, 0xFFADFF2F, 0xFF006400 };
float fillStops[5] = { 0.0, 0.4, 0.5, 0.6, 1.0 };
_gradientFillColorPalette = [[SCIGradientColorPalette alloc] initWithColors:fillColors stops:fillStops count:5];
unsigned int strokeColors[4] = {0xFFDC143C, 0xFFFF8C00, 0xFF32CD32, 0xFF32CD32 };
float strokeStops[4] = { 0.0, 0.33, 0.67, 1.0 };
_gradientStrokeColorPalette = [[SCIGradientColorPalette alloc] initWithColors:strokeColors stops:strokeStops count:4];
_transparentColorPalette = [[SCISolidColorBrushPalette alloc] initWithColor:0];
_solidStrokeColorPalette = [[SCISolidColorBrushPalette alloc] initWithColor:0xFF32CD32];
_solidFillColorPalette = [[SCISolidColorBrushPalette alloc] initWithColor:0xAA00BFFF];
}
- (NSArray<id<ISCDToolbarItem>> *)provideExampleSpecificToolbarItems {
__weak typeof(self) wSelf = self;
SCDToolbarButtonsGroup *settingsToolbar = [[SCDToolbarButtonsGroup alloc] initWithToolbarItems:@[
[[SCDToolbarItem alloc] initWithTitle:@"Waterfall3D settings" image:[SCIImage imageNamed:@"chart.settings"] andAction:^{ [wSelf p_SCD_openSettings]; }]
]];
settingsToolbar.identifier = TOOLBAR_MODIFIERS_SETTINGS;
return @[settingsToolbar];
}
- (void)p_SCD_openSettings {
_settingsPresenter = [[SCDSettingsPresenter alloc] initWithSettingsItems:[self p_SCD_createSettingsItems] andIdentifier:TOOLBAR_MODIFIERS_SETTINGS];
}
- (NSArray<id<ISCDToolbarItem>> *)p_SCD_createSettingsItems {
__weak typeof(self) wSelf = self;
SCDToolbarPopupItem *strokePopupItem = [[SCDToolbarPopupItem alloc] initWithTitles:_strokeNames selectedIndex:_currentStrokeColorPalette andAction:^(NSUInteger selectedIndex) {
self->_currentStrokeColorPalette = selectedIndex;
[wSelf p_SCD_setupStrokeColorPalette];
}];
SCDToolbarPopupItem *fillPopupItem = [[SCDToolbarPopupItem alloc] initWithTitles:_fillNames selectedIndex:_currentFillColorPalette andAction:^(NSUInteger selectedIndex) {
self->_currentFillColorPalette = selectedIndex;
[wSelf p_SCD_setupFillColorPalette];
}];
return @[
[[SCDLabeledSettingsItem alloc] initWithLabelText:@"Stroke:" item:strokePopupItem],
[[SCDLabeledSettingsItem alloc] initWithLabelText:@"Fill:" item:fillPopupItem],
[[SCDSwitchItem alloc] initWithTitle:@"Show Point Markers" isSelected:_showPointMarkers andAction:^(BOOL showPointMarkers) {
self->_showPointMarkers = showPointMarkers;
[wSelf setupPointMarker];
}],
[[SCDSwitchItem alloc] initWithTitle:@"Is Volumetric" isSelected:_isVolumetric andAction:^(BOOL isVolumetric) {
self->_isVolumetric = isVolumetric;
[wSelf setupSliceThickness];
}]
];
}
- (void)setupColorPalettes {
[self p_SCD_setupFillColorPalette];
[self p_SCD_setupStrokeColorPalette];
}
- (void)p_SCD_setupStrokeColorPalette {
switch (_currentStrokeColorPalette) {
case 0: // YAxis
_rSeries.yStrokeColorMapping = _gradientStrokeColorPalette;
_rSeries.zStrokeColorMapping = nil;
break;
case 1: // ZAxis
_rSeries.yStrokeColorMapping = nil;
_rSeries.zStrokeColorMapping = _gradientStrokeColorPalette;
break;
case 2: // Solid
_rSeries.yStrokeColorMapping = _solidStrokeColorPalette;
_rSeries.zStrokeColorMapping = _solidStrokeColorPalette;
break;
case 3: // None
_rSeries.yStrokeColorMapping = _transparentColorPalette;
_rSeries.zStrokeColorMapping = _transparentColorPalette;
break;
default:
break;
}
}
- (void)p_SCD_setupFillColorPalette {
switch (_currentFillColorPalette) {
case 0: // YAxis
_rSeries.yColorMapping = _gradientFillColorPalette;
_rSeries.zColorMapping = nil;
break;
case 1: // ZAxis
_rSeries.yColorMapping = nil;
_rSeries.zColorMapping = _gradientFillColorPalette;
break;
case 2: // Solid
_rSeries.yColorMapping = _solidFillColorPalette;
_rSeries.zColorMapping = _solidFillColorPalette;
break;
case 3: // None
_rSeries.yColorMapping = _transparentColorPalette;
_rSeries.zColorMapping = _transparentColorPalette;
break;
default:
break;
}
}
- (void)setupPointMarker {
if (_showPointMarkers) {
SCISpherePointMarker3D *pointMarker = [SCISpherePointMarker3D new];
pointMarker.fillColor = 0xFF0000FF;
pointMarker.size = 5;
_rSeries.pointMarker = pointMarker;
} else {
_rSeries.pointMarker = nil;
}
}
- (void)setupSliceThickness {
_rSeries.sliceThickness = _isVolumetric ? 5 : 0;
}
@end