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 simple iOS Candlestick chart in code. See Documentation on how to use this type here: The iOS Candlestick Chart Documentation.
SciChart’s iOS Candlestick Charts are high performance, and suitable for use in real-time trading systems, even in demanding, fast moving markets.
The SCIFastCandlestickRenderableSeries requires a SCIOhlcDataSeries, which contains one X-point and four Y-points (Open, High, Low, Close).
Candles are drawn using the UpWick, DownWick, UpBody and DownBody colors, which are used depending on whether Open > Close or not.
The Swift and Objective-C source code for the iOS and macOS Candlestick 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
//
// CandlestickChartView.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 "CandlestickChartView.h"
#import "SCDDataManager.h"
@implementation CandlestickChartView
- (Class)associatedType { return SCIChartSurface.class; }
- (void)initExample {
SCDPriceSeries *priceSeries = [SCDDataManager getPriceDataIndu];
NSInteger count = priceSeries.count;
id<ISCIAxis> xAxis = [SCICategoryDateAxis new];
xAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.0 max:0.1];
xAxis.visibleRange = [[SCIDoubleRange alloc] initWithMin:count - 30 max:count];
id<ISCIAxis> yAxis = [SCINumericAxis new];
yAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.0 max:0.1];
yAxis.autoRange = SCIAutoRange_Always;
SCIOhlcDataSeries *dataSeries = [[SCIOhlcDataSeries alloc] initWithXType:SCIDataType_Date yType:SCIDataType_Double];
[dataSeries appendValuesX:priceSeries.dateData open:priceSeries.openData high:priceSeries.highData low:priceSeries.lowData close:priceSeries.closeData];
SCIFastCandlestickRenderableSeries *rSeries = [SCIFastCandlestickRenderableSeries new];
rSeries.dataSeries = dataSeries;
rSeries.strokeUpStyle = [[SCISolidPenStyle alloc] initWithColorCode:0xFF00AA00 thickness:1];
rSeries.fillUpBrushStyle = [[SCISolidBrushStyle alloc] initWithColorCode:0x9000AA00];
rSeries.strokeDownStyle = [[SCISolidPenStyle alloc] initWithColorCode:0xFFFF0000 thickness:1];
rSeries.fillDownBrushStyle = [[SCISolidBrushStyle alloc] initWithColorCode:0x90FF0000];
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
[self.surface.xAxes add:xAxis];
[self.surface.yAxes add:yAxis];
[self.surface.renderableSeries add:rSeries];
[self.surface.chartModifiers add:[SCDExampleBaseViewController createDefaultModifiers]];
[SCIAnimations waveSeries: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
//
// CandlestickChartView.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 CandlestickChartView: SCDSingleChartViewController<SCIChartSurface> {
override var associatedType: AnyClass { return SCIChartSurface.self }
override func initExample() {
let SCDPriceSeries = SCDDataManager.getPriceDataIndu()
let size = Double(SCDPriceSeries.count)
let xAxis = SCICategoryDateAxis()
xAxis.growBy = SCIDoubleRange(min: 0, max: 0.1)
xAxis.visibleRange = SCIDoubleRange(min: size - 30, max: size)
let yAxis = SCINumericAxis()
yAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
yAxis.autoRange = .always
let dataSeries = SCIOhlcDataSeries(xType: .date, yType: .double)
dataSeries.append(x: SCDPriceSeries.dateData, open: SCDPriceSeries.openData, high: SCDPriceSeries.highData, low: SCDPriceSeries.lowData, close: SCDPriceSeries.closeData)
let rSeries = SCIFastCandlestickRenderableSeries()
rSeries.dataSeries = dataSeries
rSeries.strokeUpStyle = SCISolidPenStyle(color: 0xFF00AA00, thickness: 1.0)
rSeries.fillUpBrushStyle = SCISolidBrushStyle(color: 0x9000AA00)
rSeries.strokeDownStyle = SCISolidPenStyle(color: 0xFFFF0000, thickness: 1.0)
rSeries.fillDownBrushStyle = SCISolidBrushStyle(color: 0x90FF0000)
SCIUpdateSuspender.usingWith(surface) {
self.surface.xAxes.add(xAxis)
self.surface.yAxes.add(yAxis)
self.surface.renderableSeries.add(rSeries)
self.surface.chartModifiers.add(SCDExampleBaseViewController.createDefaultModifiers())
SCIAnimations.wave(rSeries, duration: 3.0, andEasingFunction: SCICubicEase())
}
}
}