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.
The surface mesh charts are used to explore the relationships among three-dimensional data. SciChart API allows you to add contours to the mesh to represent the three-dimensional relationships in two dimensions in your iOS apps. The contours are configurable, you may set the thickness, stroke color, opacity, offsets, intervals or even omit contours.
Please see details in SciChart iOS 3D documentation article for Configuring Contours on Surface Meshes.
The Swift and Objective-C source code for the iOS and macOS 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
//
// SurfaceMeshContours3DView.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 "SurfaceMeshContours3DView.h"
@implementation SurfaceMeshContours3DView
- (Class)associatedType { return SCIChartSurface3D.class; }
- (void)initExample {
const int w = 64;
const int h = 64;
const double ratio = 200.0 / 64.0;
SCIUniformGridDataSeries3D *ds = [[SCIUniformGridDataSeries3D alloc] initWithXType:SCIDataType_Double yType:SCIDataType_Double zType:SCIDataType_Double xSize:w zSize:h];
ds.stepX = @(0.01);
ds.stepZ = @(0.01);
for (int x = 0; x < w; x++) {
for (int z = 0; z < h; z++) {
double v = (1.0 + sin(x * 0.04 * ratio)) * 50 + (1.0 + sin(z * 0.1 * ratio)) * 50;
double cx = w / 2.0;
double cy = h / 2.0;
double r = sqrt((x - cx) * (x - cx) + (z - cy) * (z - cy)) * ratio;
double exp = MAX(0.0, 1.0 - r * 0.008);
double zValue = v * exp;
[ds updateYValue:@(zValue) atXIndex:x zIndex:z];
}
}
unsigned int colors[11] = {0xFF00FFFF, 0xFF008000, 0xFF014421, 0xFFBDB76B, 0xFFDEB887, 0xFFE9967A, 0xFFADFF2F, 0xFFFF8C00, 0xFF8B4513, 0xFFA52A2A, 0xFFA52A2A };
float stops[11] = { 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 };
SCIGradientColorPalette *palette = [[SCIGradientColorPalette alloc] initWithColors:colors stops:stops count:11];
SCISurfaceMeshRenderableSeries3D *rSeries = [SCISurfaceMeshRenderableSeries3D new];
rSeries.dataSeries = ds;
rSeries.drawMeshAs = SCIDrawMeshAs_SolidWithContours;
rSeries.stroke = 0x77228B22;
rSeries.maximum = 150;
rSeries.strokeThickness = 2.0;
rSeries.drawSkirt = YES;
rSeries.cellHardnessFactor = 1.0;
rSeries.meshColorPalette = palette;
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.renderableSeries add:rSeries];
[self.surface.chartModifiers add:[SCDExampleBaseViewController createDefaultModifiers3D]];
self.surface.camera = [SCICamera3D new];
[self.surface.camera.position assignX:-1300 y:1300 z:-1300];
[self.surface.worldDimensions assignX:600 y:300 z:300];
}];
}
@end
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// SurfaceMeshContours3DView.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 SurfaceMeshContours3DView: SCDSingleChartViewController<SCIChartSurface3D> {
override var associatedType: AnyClass { return SCIChartSurface3D.self }
override func initExample() {
let w = 64;
let h = 64;
let ratio = 200.0 / 64.0;
let ds = SCIUniformGridDataSeries3D(xType: .double, yType: .double, zType: .double, xSize: w, zSize: h)
ds.set(stepX: 0.01)
ds.set(stepZ: 0.01)
for x in 0 ..< w {
for z in 0 ..< h {
let v = (1.0 + sin(Double(x) * 0.04 * ratio)) * 50.0 + (1.0 + sin(Double(z) * 0.1 * ratio)) * 50.0
let cx: Double = Double(w) / 2.0
let cy: Double = Double(h) / 2.0
let r: Double = sqrt((Double(x) - cx) * (Double(x) - cx) + (Double(z) - cy) * (Double(z) - cy)) * ratio
let exp: Double = Double.maximum(0.0, 1.0 - r * 0.008)
let yValue: Double = v * exp
ds.update(y: yValue, atX: x, z: z)
}
}
let colors: [UInt32] = [0xFF00FFFF, 0xFF008000, 0xFF014421, 0xFFBDB76B, 0xFFDEB887, 0xFFE9967A, 0xFFADFF2F, 0xFFFF8C00, 0xFF8B4513, 0xFFA52A2A, 0xFFA52A2A]
let stops: [Float] = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
let stroke: UInt32 = 0x77228B22
let palette = SCIGradientColorPalette(colors: colors, stops: stops, count: 11)
let rSeries = SCISurfaceMeshRenderableSeries3D()
rSeries.dataSeries = ds
rSeries.drawMeshAs = .solidWithContours
rSeries.contourStrokeThickness = 2.0
rSeries.stroke = stroke
rSeries.maximum = 150
rSeries.strokeThickness = 2.0
rSeries.drawSkirt = true
rSeries.cellHardnessFactor = 1.0
rSeries.meshColorPalette = palette
rSeries.opacity = 0.8
SCIUpdateSuspender.usingWith(surface) {
self.surface.xAxis = SCINumericAxis3D()
self.surface.yAxis = SCINumericAxis3D()
self.surface.zAxis = SCINumericAxis3D()
self.surface.renderableSeries.add(rSeries)
self.surface.chartModifiers.add(SCDExampleBaseViewController.createDefaultModifiers3D())
self.surface.camera = SCICamera3D()
self.surface.camera.position.assignX(-1300, y: 1300, z: -1300)
self.surface.worldDimensions.assignX(600, y: 300, z: 300)
}
}
}