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.
Generates a Scatter chart in code. See Documentation on how to use this type here: The iOS Scatter Chart Documentation.
The SCIXyScatterRenderableSeries can be used to render a high performance iOS Scatter Chart in either Swift or Objective C. SciChart iOS supports millions of points out of the box, and is suitable for use in real-time scientific, medical and trading applications.
Data is provided by a DataSeries, e.g. the SCIXyDataSeries, SCIXyyDataSeries (uses Y1 only) or SCIOhlcDataSeries (renders close).
The scatter chart uses the PointMarker API to define the marker shape and size. This can be customized in code or you can create your own Point-Markers using our SCISpritePointMarker or SCIPointMarkerBase type.
Tip!
Perhaps you wanted a scatter point with a line? If so you can do this using the SCIFastLineRenderableSeries and setting the PointMarker property.
The Swift and Objective-C source code for the iOS and macOS Scatter 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
//
// ScatterSeriesChartView.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 "ScatterSeriesChartView.h"
#import "SCDDataManager.h"
@implementation ScatterSeriesChartView
- (Class)associatedType { return SCIChartSurface.class; }
- (void)initExample {
id<ISCIAxis> xAxis = [SCINumericAxis new];
xAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.1 max:0.1];
id<ISCIAxis> yAxis = [SCINumericAxis new];
yAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.1 max:0.1];
id<ISCIRenderableSeries> rSeries1 = [self getScatterRenderableSeries:[SCITrianglePointMarker new] colorCode:0xFFffeb01 negative:NO];
id<ISCIRenderableSeries> rSeries2 = [self getScatterRenderableSeries:[SCIEllipsePointMarker new] colorCode:0xFFffa300 negative:NO];
id<ISCIRenderableSeries> rSeries3 = [self getScatterRenderableSeries:[SCITrianglePointMarker new] colorCode:0xFFff6501 negative:YES];
id<ISCIRenderableSeries> rSeries4 = [self getScatterRenderableSeries:[SCIEllipsePointMarker new] colorCode:0xFFffa300 negative:YES];
SCIYAxisDragModifier *yAxisDragModifier = [SCIYAxisDragModifier new];
yAxisDragModifier.dragMode = SCIAxisDragMode_Pan;
SCICursorModifier *cursorModifier = [SCICursorModifier new];
cursorModifier.receiveHandledEvents = YES;
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
[self.surface.xAxes add:xAxis];
[self.surface.yAxes add:yAxis];
[self.surface.renderableSeries add:rSeries1];
[self.surface.renderableSeries add:rSeries2];
[self.surface.renderableSeries add:rSeries3];
[self.surface.renderableSeries add:rSeries4];
[self.surface.chartModifiers addAll:[SCIZoomExtentsModifier new], [SCIPinchZoomModifier new], cursorModifier, [SCIXAxisDragModifier new], yAxisDragModifier, nil];
}];
}
- (id<ISCIRenderableSeries>) getScatterRenderableSeries:(id<ISCIPointMarker>)pointMarker colorCode:(unsigned int)colorCode negative:(BOOL)negative {
SCIXyDataSeries *dataSeries = [[SCIXyDataSeries alloc] initWithXType:SCIDataType_Int yType:SCIDataType_Double];
dataSeries.seriesName = ([pointMarker isKindOfClass:SCIEllipsePointMarker.class])
? negative ? @"Negative Ellipse" : @"Positive Ellipse"
: negative ? @"Negative" : @"Positive";
for (int i = 0; i < 200; i++) {
double time = i < 100 ? randf(0, i + 10) / 100 : randf(0, 200 - i + 10) / 100;
double y = negative ? -time * time * time : time * time * time;
[dataSeries appendX:@(i) y:@(y)];
}
pointMarker.fillStyle = [[SCISolidBrushStyle alloc] initWithColorCode:colorCode];
pointMarker.strokeStyle = [[SCISolidPenStyle alloc] initWithColorCode:0xFFFFFFFF thickness:0.1];
pointMarker.size = CGSizeMake(6, 6);
SCIXyScatterRenderableSeries *rSeries = [SCIXyScatterRenderableSeries new];
rSeries.dataSeries = dataSeries;
rSeries.pointMarker = pointMarker;
[SCIAnimations waveSeries:rSeries duration:3.0 delay:0.3 andEasingFunction:[SCICubicEase new]];
return rSeries;
}
@end
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// ScatterSeriesChartView.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 ScatterSeriesChartView: SCDSingleChartViewController<SCIChartSurface> {
override var associatedType: AnyClass { return SCIChartSurface.self }
override func initExample() {
let xAxis = SCINumericAxis()
xAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
let yAxis = SCINumericAxis()
yAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
let rSeries1 = getScatterRenderableSeriesWith(pointMarker: SCITrianglePointMarker(), colorCode: 0xFFffeb01, negative: false)
let rSeries2 = getScatterRenderableSeriesWith(pointMarker: SCIEllipsePointMarker(), colorCode: 0xFFffa300, negative: false)
let rSeries3 = getScatterRenderableSeriesWith(pointMarker: SCITrianglePointMarker(), colorCode: 0xFFff6501, negative: true)
let rSeries4 = getScatterRenderableSeriesWith(pointMarker: SCIEllipsePointMarker(), colorCode: 0xFFffa300, negative: true)
let yAxisDragModifier = SCIYAxisDragModifier()
yAxisDragModifier.dragMode = .pan
let cursorModifier = SCICursorModifier()
cursorModifier.receiveHandledEvents = true
SCIUpdateSuspender.usingWith(surface) {
self.surface.xAxes.add(xAxis)
self.surface.yAxes.add(yAxis)
self.surface.renderableSeries.add(rSeries1)
self.surface.renderableSeries.add(rSeries2)
self.surface.renderableSeries.add(rSeries3)
self.surface.renderableSeries.add(rSeries4)
self.surface.chartModifiers.add(items: SCIZoomExtentsModifier(), SCIPinchZoomModifier(), cursorModifier, SCIXAxisDragModifier(), yAxisDragModifier)
}
}
fileprivate func getScatterRenderableSeriesWith(pointMarker: ISCIPointMarker, colorCode: UInt32, negative: Bool) -> SCIXyScatterRenderableSeries {
let dataSeries = SCIXyDataSeries(xType: .int, yType: .double)
dataSeries.seriesName = pointMarker is SCIEllipsePointMarker
? negative ? "Negative Ellipse" : "Positive Ellipse"
: negative ? "Negative" : "Positive"
for i in 0 ..< 200 {
let time = i < 100 ? randf(0, Double(i + 10)) / 100 : randf(0, Double(200 - i + 10)) / 100
let y = negative ? -time * time * time : time * time * time
dataSeries.append(x: i, y: y)
}
pointMarker.fillStyle = SCISolidBrushStyle(color: colorCode)
pointMarker.strokeStyle = SCISolidPenStyle(color: 0xfffffff, thickness: 0.1)
pointMarker.size = CGSize(width: 6, height: 6)
let rSeries = SCIXyScatterRenderableSeries()
rSeries.dataSeries = dataSeries
rSeries.pointMarker = pointMarker
SCIAnimations.wave(rSeries, duration: 3.0, delay: 0.3, andEasingFunction: SCICubicEase())
return rSeries
}
}