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.
SciChart allows you to have multiple series on an iOS chart, it is also possible to add and remove series programmatically in SciChart 3D iOS chart library.
The Swift and Objective-C source code for the iOS and macOS Add remove Series 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
//
// ManipulateSeries3DChartView.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 "ManipulateSeries3DChartView.h"
#import "SCDButtonsTopPanel.h"
#import "SCDToolbarButton.h"
#import "SCDDataManager.h"
#import "SCDRandomUtil.h"
#import "SCDToolbarButtonsGroup.h"
static const int MAX_SERIES_AMOUNT = 15;
static const int DATA_POINTS_COUNT = 15;
@implementation ManipulateSeries3DChartView
- (Class)associatedType { return SCIChartSurface3D.class; }
- (NSArray<SCDToolbarItem *> *)panelItems {
__weak typeof(self) wSelf = self;
return @[
[[SCDToolbarButton alloc] initWithTitle:@"Add Series" image:nil andAction:^{ [wSelf add]; }],
[[SCDToolbarButton alloc] initWithTitle:@"Remove Series" image:nil andAction:^{ [wSelf remove]; }],
[[SCDToolbarButton alloc] initWithTitle:@"Clear" image:nil andAction:^{ [wSelf.surface.renderableSeries clear]; }],
];
}
#if TARGET_OS_OSX
- (NSArray<id<ISCDToolbarItem>> *)provideExampleSpecificToolbarItems {
return @[[[SCDToolbarButtonsGroup alloc] initWithToolbarItems:self.panelItems]];
}
#elif TARGET_OS_IOS
- (SCIView *)providePanel {
return [[SCDButtonsTopPanel alloc] initWithToolbarItems:self.panelItems];
}
#endif
- (void)initExample {
SCINumericAxis3D *xAxis = [SCINumericAxis3D new];
xAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.1 max:0.1];
xAxis.autoRange = SCIAutoRange_Always;
SCINumericAxis3D *yAxis = [SCINumericAxis3D new];
yAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.1 max:0.1];
yAxis.autoRange = SCIAutoRange_Always;
SCINumericAxis3D *zAxis = [SCINumericAxis3D new];
zAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.1 max:0.1];
zAxis.autoRange = SCIAutoRange_Always;
SCILegendModifier3D *legendModifier3D = [SCILegendModifier3D new];
legendModifier3D.showSeriesMarkers = NO;
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
self.surface.xAxis = xAxis;
self.surface.yAxis = yAxis;
self.surface.zAxis = zAxis;
[self.surface.chartModifiers add:[SCDExampleBaseViewController createDefaultModifiers3D]];
[self.surface.chartModifiers add:legendModifier3D];
}];
}
- (void)add {
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
SCIRenderableSeries3DCollection *renderableSeries = self.surface.renderableSeries;
if (renderableSeries.count >= MAX_SERIES_AMOUNT) return;
SCIXyzDataSeries3D *ds = [[SCIXyzDataSeries3D alloc] initWithXType:SCIDataType_Double yType:SCIDataType_Double zType:SCIDataType_Double];
SCIPointMetadataProvider3D *metadataProvider = [SCIPointMetadataProvider3D new];
for (int i = 0; i < DATA_POINTS_COUNT; ++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];
[ds appendX:@(x) y:@(y) z:@(z)];
SCIPointMetadata3D *metaData = [[SCIPointMetadata3D alloc] initWithVertexColor:[SCDDataManager randomColor] andScale:[SCDDataManager randomScale]];
[metadataProvider.metadata addObject:metaData];
}
SCIScatterRenderableSeries3D *rSeries = [SCIScatterRenderableSeries3D new];
rSeries.dataSeries = ds;
rSeries.metadataProvider = metadataProvider;
const int randValue = randi(0, 6);
switch (randValue) {
case 0:
rSeries.pointMarker = [SCICubePointMarker3D new];
break;
case 1:
rSeries.pointMarker = [SCIEllipsePointMarker3D new];
break;
case 2:
rSeries.pointMarker = [SCIPyramidPointMarker3D new];
break;
case 3:
rSeries.pointMarker = [SCIQuadPointMarker3D new];
break;
case 4:
rSeries.pointMarker = [SCISpherePointMarker3D new];
break;
case 5:
rSeries.pointMarker = [SCITrianglePointMarker3D new];
break;
default:
break;
}
[renderableSeries add:rSeries];
const NSInteger index = [renderableSeries indexOf:rSeries];
ds.seriesName = [NSString stringWithFormat:@"Series %ld", index];
}];
}
- (void)remove {
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
SCIRenderableSeries3DCollection *renderableSeries = self.surface.renderableSeries;
if (!renderableSeries.isEmpty) {
[renderableSeries removeAt:0];
}
}];
}
@end
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// ManipulateSeries3DChartView.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.
//******************************************************************************
private let MaxSeriesCount = 15
private let MaxPointsCount = 15
class ManipulateSeries3DChartView: SCDSingleChartWithTopPanelViewController<SCIChartSurface3D> {
override var associatedType: AnyClass { return SCIChartSurface3D.self }
private var panelItems: [ISCDToolbarItemModel] {
return [
SCDToolbarButton(title: "Add Series", image: nil, andAction: { [weak self] in self?.add() }),
SCDToolbarButton(title: "Remove Series", image: nil, andAction: { [weak self] in self?.remove() }),
SCDToolbarButton(title: "Clear", image: nil, andAction: { [weak self] in self?.surface.renderableSeries.clear() })
]
}
#if os(OSX)
override func provideExampleSpecificToolbarItems() -> [ISCDToolbarItem] {
return [SCDToolbarButtonsGroup(toolbarItems: panelItems)]
}
#elseif os(iOS)
override func providePanel() -> SCIView {
return SCDButtonsTopPanel(toolbarItems: self.panelItems)
}
#endif
override func initExample() {
let xAxis = SCINumericAxis3D()
xAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
xAxis.autoRange = .always
let yAxis = SCINumericAxis3D()
yAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
yAxis.autoRange = .always
let zAxis = SCINumericAxis3D()
zAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
zAxis.autoRange = .always
let legendModifier = SCILegendModifier3D()
legendModifier.showSeriesMarkers = false
SCIUpdateSuspender.usingWith(surface) {
self.surface.xAxis = xAxis
self.surface.yAxis = yAxis
self.surface.zAxis = zAxis
self.surface.chartModifiers.add(items: SCDExampleBaseViewController.createDefaultModifiers3D(), legendModifier)
}
}
fileprivate func add() {
let seriesCollection = surface.renderableSeries
guard surface.renderableSeries.count < MaxPointsCount else { return }
let dataSeries = SCIXyzDataSeries3D(xType: .double, yType: .double, zType: .double)
let pointMetaDataProvider = SCIPointMetadataProvider3D()
for _ in 0 ..< MaxPointsCount {
let x = SCDDataManager.getGaussianRandomNumber(5, stdDev: 1.5)
let y = SCDDataManager.getGaussianRandomNumber(5, stdDev: 1.5)
let z = SCDDataManager.getGaussianRandomNumber(5, stdDev: 1.5)
dataSeries.append(x: x, y: y, z: z)
let metadata = SCIPointMetadata3D(vertexColor: SCDDataManager.randomColor(), andScale: SCDDataManager.randomScale())
pointMetaDataProvider.metadata.add(metadata)
}
let rSeries = SCIScatterRenderableSeries3D()
rSeries.dataSeries = dataSeries
rSeries.metadataProvider = pointMetaDataProvider
rSeries.pointMarker = SCIEllipsePointMarker3D()
let randValue = arc4random_uniform(5)
switch randValue {
case 0:
rSeries.pointMarker = SCIEllipsePointMarker3D()
case 1...2:
rSeries.pointMarker = SCIPyramidPointMarker3D()
case 3...4:
rSeries.pointMarker = SCISpherePointMarker3D()
default:
break;
}
seriesCollection.add(rSeries)
let index = seriesCollection.index(of: rSeries)
dataSeries.seriesName = "Series \(index)"
}
fileprivate func remove() {
if !surface.renderableSeries.isEmpty {
SCIUpdateSuspender.usingWith(surface) {
self.surface.renderableSeries.remove(at: 0)
}
}
}
}