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.
This is an example for iOS Waterfall 3D chart. It shows how using SciChart iOS 3D Charting Library API you can easily create Simple Waterfall Chart in 3D, that is initially looks like a series of slices or mountain shapes that appear side by side. It is rendered with SCIWaterfallRenderableSeries3D series.
The SCIWaterfallRenderableSeries3D series type provides a number of configurable chart types in SciChart iOS 3D, including:
Please read more about The Waterfall 3D Chart Type in SciChart iOS Documentation.
The Swift and Objective-C source code for the iOS and macOS Simple Waterfall Chart 3D 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
//
// SimpleWaterfall3DChartView.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 "SimpleWaterfall3DChartView.h"
#import "SCDRadix2FFT.h"
#import "SCDRandomUtil.h"
const int PointsPerSlice = 128;
const int SliceCount = 20;
@implementation SimpleWaterfall3DChartView {
SCDRadix2FFT *_radixTransform;
}
- (void)initExample {
_radixTransform = [[SCDRadix2FFT alloc] initWithSize:PointsPerSlice];
SCIWaterfallDataSeries3D *ds = [[SCIWaterfallDataSeries3D alloc] initWithXType:SCIDataType_Double yType:SCIDataType_Double zType:SCIDataType_Double xSize:PointsPerSlice zSize:SliceCount];
ds.startX = @(10.0);
ds.startZ = @(1.0);
[self fill:ds];
self.rSeries = [SCIWaterfallRenderableSeries3D new];
self.rSeries.dataSeries = ds;
[self setupColorPalettes];
[self setupSliceThickness];
[self setupPointMarker];
self.rSeries.metadataProvider = [SCIDefaultSelectableMetadataProvider3D new];
self.rSeries.opacity = 0.8;
[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 addAll:[SCDExampleBaseViewController createDefaultModifiers3D], [SCIVertexSelectionModifier3D new], nil];
}];
}
- (void)fill:(SCIWaterfallDataSeries3D *)dataSeries {
const int Count = PointsPerSlice * 2;
double *re = new double[Count];
double *im = new double[Count];
for (int sliceIndex = 0; sliceIndex < SliceCount; ++sliceIndex) {
for (int i = 0; i < Count; ++ i) {
re[i] = 2.0 * sin(M_PI * i / 10.0) +
5.0 * sin(M_PI * i / 5.0) +
2.0 * randf(0.0, 1.0);
im[i] = -10.0;
}
[_radixTransform runWithReals:re imaginaries:im];
double scaleCoef = pow(1.5, sliceIndex * 0.3) / pow(1.5, SliceCount * 0.3);
for (int pointIndex = 0; pointIndex < PointsPerSlice; ++pointIndex) {
double reValue = re[pointIndex];
double imValue = im[pointIndex];
double mag = sqrt(reValue * reValue + imValue * imValue);
double yVal = (randi(0, 10) + 10) * log10(mag / PointsPerSlice);
yVal = (yVal < -25 || yVal > -5)
? (yVal < -25) ? -25.0 : (randi(0, 9) - 6)
: yVal;
[dataSeries updateYValue:@((-yVal * scaleCoef)) atXIndex:pointIndex zIndex:sliceIndex];
}
}
delete[] re;
delete[] im;
}
@end
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// SimpleWaterfall3DChartView.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 SimpleWaterfall3DChartView: SCDWaterfall3DChartViewControllerBase {
let PointsPerSlice = 128;
let SliceCount = 20;
let radixTransform = SCDRadix2FFT(size: 128)
override func initExample() {
let ds = SCIWaterfallDataSeries3D(xType: .double, yType: .double, zType: .double, xSize: PointsPerSlice, zSize: SliceCount)
ds.set(startX: 10.0)
ds.set(startZ: 1.0)
fill(dataSeries: ds)
rSeries = SCIWaterfallRenderableSeries3D()
rSeries.dataSeries = ds
setupColorPalettes()
setupPointMarker()
setupSliceThickness()
rSeries.metadataProvider = SCIDefaultSelectableMetadataProvider3D()
rSeries.opacity = 0.8;
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(items: SCDExampleBaseViewController.createDefaultModifiers3D(), SCIVertexSelectionModifier3D())
}
}
func fill(dataSeries: SCIWaterfallDataSeries3D) {
let count = PointsPerSlice * 2;
let re = UnsafeMutablePointer<Double>.allocate(capacity: count)
let im = UnsafeMutablePointer<Double>.allocate(capacity: count)
defer {
re.deallocate()
im.deallocate()
}
for sliceIndex in 0 ..< SliceCount {
for i in 0 ..< count {
re[i] = 2.0 * sin(Double.pi * Double(i) / 10.0) +
5.0 * sin(Double.pi * Double(i) / 5.0) +
2.0 * Double.random(in: 0.0 ... 1.0)
im[i] = -10.0;
}
radixTransform.run(withReals: re, imaginaries: im)
let scaleCoef = pow(1.5, Double(sliceIndex) * 0.3) / pow(1.5, Double(SliceCount) * 0.3)
for pointIndex in 0 ..< PointsPerSlice {
let reValue = re[pointIndex]
let imValue = im[pointIndex]
let mag = sqrt(reValue * reValue + imValue * imValue)
var yVal = Double(Int.random(in: 0 ..< 10) + 10) * log10(mag / Double(PointsPerSlice))
yVal = (yVal < -25 || yVal > -5)
? (yVal < -25) ? -25.0 : Double(Int.random(in: 0 ..< 9) - 6)
: yVal
dataSeries.update(y: -yVal * scaleCoef, atX: pointIndex, z: sliceIndex)
}
}
}
}