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.
In SciChart it is possible to link multiple iOS Charts so that they behave as one.
Linked charts zoom together, scroll together, pan together and tooltips interact with all the charts in the shared group.
This technique can be used to create multi-pane stock charts, or an ECG / EKG, or simply link together charts where you wish to see multiple different time-series one above another.
Please read more in SciChart iOS Tutorials:Tutorial – Linking Multiple Charts
The Swift and Objective-C source code for the iOS and macOS Linking Multiple Charts 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-2020. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// SCDSyncMultipleChartsViewController.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 "SCDTwoChartsViewController.h"
@implementation SCDTwoChartsViewController
- (void)loadView {
[super loadView];
self.view = [SCIView new];
self.view.autoresizingMask = SCIAutoresizingFlexible;
SCIView<ISCIChartSurfaceBase> *surface1 = [[self.associatedType alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
surface1.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:surface1];
SCIView<ISCIChartSurfaceBase> *surface2 = [[self.associatedType alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
surface2.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:surface2];
[self.view addConstraints:@[
[surface1.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
[surface1.topAnchor constraintEqualToAnchor:self.view.topAnchor],
[surface1.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
[surface1.bottomAnchor constraintEqualToAnchor:surface2.topAnchor],
[surface1.heightAnchor constraintEqualToAnchor:surface2.heightAnchor],
[surface2.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
[surface2.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
[surface2.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
]];
_surface1 = surface1;
_surface2 = surface2;
}
- (void)tryUpdateChartTheme:(SCIChartTheme)theme {
[SCIThemeManager applyTheme:theme toThemeable:self.surface1];
[SCIThemeManager applyTheme:theme toThemeable:self.surface2];
}
@end
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// SyncMultipleChartsView.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 "SyncMultipleChartsView.h"
#import "SCDDataManager.h"
static int const PointsCount = 500;
@implementation SyncMultipleChartsView {
SCIDoubleRange *_sharedXRange;
SCIDoubleRange *_sharedYRange;
}
- (Class)associatedType { return SCIChartSurface.class; }
- (BOOL)showDefaultModifiersInToolbar { return NO; }
- (void)initExample {
_sharedXRange = [[SCIDoubleRange alloc] initWithMin:0 max:1];
_sharedYRange = [[SCIDoubleRange alloc] initWithMin:0 max:1];
[self initChart:self.surface1];
[self initChart:self.surface2];
}
- (void)initChart:(SCIChartSurface *)surface {
id<ISCIAxis> xAxis = [SCINumericAxis new];
xAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.1 max:0.1];
xAxis.visibleRange = _sharedXRange;
id<ISCIAxis> yAxis = [SCINumericAxis new];
yAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.1 max:0.1];
yAxis.visibleRange = _sharedYRange;
SCIXyDataSeries *dataSeries = [[SCIXyDataSeries alloc] initWithXType:SCIDataType_Double yType:SCIDataType_Double];
for (int i = 0; i < PointsCount; i++) {
[dataSeries appendX:@(i) y:@(PointsCount * sin(i * M_PI * 0.1) / i)];
}
SCIFastLineRenderableSeries *rSeries = [SCIFastLineRenderableSeries new];
rSeries.dataSeries = dataSeries;
rSeries.strokeStyle = [[SCISolidPenStyle alloc] initWithColor:SCIColor.greenColor thickness:1.0];
SCIRolloverModifier *rolloverModifier = [SCIRolloverModifier new];
rolloverModifier.receiveHandledEvents = YES;
rolloverModifier.eventsGroupTag = @"SharedEventGroup";
[SCIUpdateSuspender usingWithSuspendable:surface withBlock:^{
[surface.xAxes add:xAxis];
[surface.yAxes add:yAxis];
[surface.renderableSeries add:rSeries];
[surface.chartModifiers addAll:[SCIZoomExtentsModifier new], [SCIPinchZoomModifier new], rolloverModifier, [SCIXAxisDragModifier new], [SCIYAxisDragModifier new], nil];
[surface zoomExtents];
[SCIAnimations sweepSeries:rSeries duration:3.0 andEasingFunction:[SCICubicEase new]];
}];
}
@end
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// SyncMultipleChartsView.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 SyncMultipleChartsView: SCDTwoChartsViewController<SCIChartSurface> {
override var associatedType: AnyClass { return SCIChartSurface.self }
let PointsCount = 500
let SharedXRange = SCIDoubleRange(min: 0, max: 1)
let SharedYRange = SCIDoubleRange(min: 0, max: 1)
override var showDefaultModifiersInToolbar: Bool { return false }
override func initExample() {
initChart(surface: surface1!)
initChart(surface: surface2!)
}
fileprivate func initChart(surface: SCIChartSurface) {
let xAxis = SCINumericAxis()
xAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
xAxis.visibleRange = SharedXRange
let yAxis = SCINumericAxis()
yAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
yAxis.visibleRange = SharedYRange
let dataSeries = SCIXyDataSeries(xType: .double, yType: .double)
for i in 0 ..< PointsCount {
dataSeries.append(x: i, y: Double(PointsCount) * sin(Double(i) * .pi * 0.1) / Double(i))
}
let rSeries = SCIFastLineRenderableSeries()
rSeries.dataSeries = dataSeries
rSeries.strokeStyle = SCISolidPenStyle(color: .green, thickness: 1.0)
let rolloverModifier = SCIRolloverModifier()
rolloverModifier.receiveHandledEvents = true
rolloverModifier.eventsGroupTag = "SharedEventGroup"
SCIUpdateSuspender.usingWith(surface) {
surface.xAxes.add(xAxis)
surface.yAxes.add(yAxis)
surface.renderableSeries.add(rSeries)
surface.chartModifiers.add(items: SCIZoomExtentsModifier(), SCIPinchZoomModifier(), rolloverModifier, SCIXAxisDragModifier(), SCIYAxisDragModifier())
surface.zoomExtents()
SCIAnimations.sweep(rSeries, duration: 3.0, easingFunction: SCICubicEase())
}
}
}