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 example demonstrates how the Spline line chart in iOS can be created using SCISplineLineRenderableSeries type. The iOS Spline line API includes the algorithm to smooth the line, when you have too many data points and displaying raw data makes it difficult to see the trends. This gives a slick look to the iOS charts and nice user experience to the customers of your iOS applications.
Spline Line Series Features:
Read more in the documentation for iOS Spline smoothing Line Series.
See also: Spline Mountain Series and Spline Band series as well.
The Swift and Objective-C source code for the iOS and macOS Spline Line 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
//
// SplineLineChartView.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 "SplineLineChartView.h"
@implementation SplineLineChartView
- (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.2 max:0.2];
SCIXyDataSeries *dataSeries = [[SCIXyDataSeries alloc] initWithXType:SCIDataType_Int yType:SCIDataType_Int];
int yValues[] = {50, 35, 61, 58, 50, 50, 40, 53, 55, 23, 45, 12, 59, 60};
for (unsigned long i = 0; i < sizeof(yValues) / sizeof(yValues[0]); i++) {
[dataSeries appendX:@(i) y:@(yValues[i])];
}
SCIEllipsePointMarker *ellipsePointMarker = [SCIEllipsePointMarker new];
ellipsePointMarker.strokeStyle = [[SCISolidPenStyle alloc] initWithColorCode:0xFF006400 thickness:1.0 strokeDashArray:NULL antiAliasing:YES];
ellipsePointMarker.fillStyle = [[SCISolidBrushStyle alloc] initWithColorCode:0xFFFFFFFF];
ellipsePointMarker.size = CGSizeMake(7, 7);
SCIFastLineRenderableSeries *lineSeries = [SCIFastLineRenderableSeries new];
lineSeries.dataSeries = dataSeries;
lineSeries.pointMarker = ellipsePointMarker;
lineSeries.strokeStyle = [[SCISolidPenStyle alloc] initWithColorCode:0xFF4282B4 thickness:1.0 strokeDashArray:NULL antiAliasing:YES];
SCISplineLineRenderableSeries *splineLineSeries = [SCISplineLineRenderableSeries new];
splineLineSeries.dataSeries = dataSeries;
splineLineSeries.strokeStyle = [[SCISolidPenStyle alloc] initWithColorCode:0xFF006400 thickness:2.0 strokeDashArray:NULL antiAliasing:YES];
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
[self.surface.xAxes add:xAxis];
[self.surface.yAxes add:yAxis];
[self.surface.renderableSeries addAll:lineSeries, splineLineSeries, nil];
[self.surface.chartModifiers add:[SCDExampleBaseViewController createDefaultModifiers]];
[SCIAnimations sweepSeries:lineSeries duration:3.0 andEasingFunction:[SCICubicEase new]];
[SCIAnimations sweepSeries:splineLineSeries duration:3.0 andEasingFunction:[SCICubicEase new]];
}];
}
@end
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2020. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// SplineLineChartView.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 SplineLineChartView: 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.2, max: 0.2)
let dataSeries = SCIXyDataSeries(xType: .int, yType: .int)
let yValues = [50, 35, 61, 58, 50, 50, 40, 53, 55, 23, 45, 12, 59, 60]
for i in 0 ..< yValues.count {
dataSeries.append(x: i, y: yValues[i])
}
let ellipsePointMarker = SCIEllipsePointMarker()
ellipsePointMarker.strokeStyle = SCISolidPenStyle(color: 0xFF006400, thickness: 1.0)
ellipsePointMarker.fillStyle = SCISolidBrushStyle(color: 0xFFFFFFFF)
ellipsePointMarker.size = CGSize(width: 7, height: 7)
let lineSeries = SCIFastLineRenderableSeries()
lineSeries.dataSeries = dataSeries
lineSeries.pointMarker = ellipsePointMarker
lineSeries.strokeStyle = SCISolidPenStyle(color: 0xFF4282B4, thickness: 1.0, strokeDashArray: nil, antiAliasing: true)
let splineLineSeries = SCISplineLineRenderableSeries()
splineLineSeries.dataSeries = dataSeries
lineSeries.strokeStyle = SCISolidPenStyle(color: 0xFF006400, thickness: 2.0, strokeDashArray: nil, antiAliasing: true)
SCIUpdateSuspender.usingWith(surface) {
self.surface.xAxes.add(xAxis)
self.surface.yAxes.add(yAxis)
self.surface.renderableSeries.add(items: lineSeries, splineLineSeries)
self.surface.chartModifiers.add(SCDExampleBaseViewController.createDefaultModifiers())
SCIAnimations.sweep(lineSeries, duration: 3.0, easingFunction: SCICubicEase())
SCIAnimations.sweep(splineLineSeries, duration: 3.0, easingFunction: SCICubicEase())
}
}
}