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 Stacked Column chart in code-behind. See Documentation on how to use this type here: The IOS Stacked Column Chart.
The SCIStackedColumnRenderableSeries API can be used to render columns stacked above each other, or side by side in either Swift or Objective C. Grouping is performed when you place multiple SCIStackedColumnRenderableSeries into a SCIVerticallyStackedMountainsCollection or for horizontal column groups, the SCIHorizontallyStackedColumnsCollection.
Data is provided by a DataSeries, e.g. the SCIXyDataSeries, SCIXyyDataSeries (uses Y1 only) or SCIOhlcDataSeries (renders close).
Mountains are styled using the Stroke (outline) and Fill (fill).
The Swift 4 and Objective-C source code for the iOS Stacked Column 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
//
// StackedColumnChartView.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 "StackedColumnChartView.h"
#import "SCDDataManager.h"
@implementation StackedColumnChartView
- (Class)associatedType { return SCIChartSurface.class; }
- (void)initExample {
id<ISCIAxis> xAxis = [SCINumericAxis new];
id<ISCIAxis> yAxis = [SCINumericAxis new];
double porkData[] = {10, 13, 7, 16, 4, 6, 20, 14, 16, 10, 24, 11};
double vealData[] = {12, 17, 21, 15, 19, 18, 13, 21, 22, 20, 5, 10};
double tomatoesData[] = {7, 30, 27, 24, 21, 15, 17, 26, 22, 28, 21, 22};
double cucumberData[] = {16, 10, 9, 8, 22, 14, 12, 27, 25, 23, 17, 17};
double pepperData[] = {7, 24, 21, 11, 19, 17, 14, 27, 26, 22, 28, 16};
SCIXyDataSeries *ds1 = [[SCIXyDataSeries alloc] initWithXType:SCIDataType_Double yType:SCIDataType_Double];
ds1.seriesName = @"Pork Series";
SCIXyDataSeries *ds2 = [[SCIXyDataSeries alloc] initWithXType:SCIDataType_Double yType:SCIDataType_Double];
ds2.seriesName = @"Veal Series";
SCIXyDataSeries *ds3 = [[SCIXyDataSeries alloc] initWithXType:SCIDataType_Double yType:SCIDataType_Double];
ds3.seriesName = @"Tomato Series";
SCIXyDataSeries *ds4 = [[SCIXyDataSeries alloc] initWithXType:SCIDataType_Double yType:SCIDataType_Double];
ds4.seriesName = @"Cucumber Series";
SCIXyDataSeries *ds5 = [[SCIXyDataSeries alloc] initWithXType:SCIDataType_Double yType:SCIDataType_Double];
ds5.seriesName = @"Pepper Series";
int data = 1992;
int size = sizeof(porkData) / sizeof(porkData[0]);
for (int i = 0; i < size; i++) {
double xValue = data + i;
[ds1 appendX:@(xValue) y:@(porkData[i])];
[ds2 appendX:@(xValue) y:@(vealData[i])];
[ds3 appendX:@(xValue) y:@(tomatoesData[i])];
[ds4 appendX:@(xValue) y:@(cucumberData[i])];
[ds5 appendX:@(xValue) y:@(pepperData[i])];
}
SCIVerticallyStackedColumnsCollection *verticalCollection1 = [SCIVerticallyStackedColumnsCollection new];
[verticalCollection1 add:[self getRenderableSeriesWithDataSeries:ds1 FillColor:0xff226fb7]];
[verticalCollection1 add:[self getRenderableSeriesWithDataSeries:ds2 FillColor:0xffff9a2e]];
SCIVerticallyStackedColumnsCollection *verticalCollection2 = [SCIVerticallyStackedColumnsCollection new];
[verticalCollection2 add:[self getRenderableSeriesWithDataSeries:ds3 FillColor:0xffdc443f]];
[verticalCollection2 add:[self getRenderableSeriesWithDataSeries:ds4 FillColor:0xffaad34f]];
[verticalCollection2 add:[self getRenderableSeriesWithDataSeries:ds5 FillColor:0xff8562b4]];
SCIHorizontallyStackedColumnsCollection *columnCollection = [SCIHorizontallyStackedColumnsCollection new];
[columnCollection add:verticalCollection1];
[columnCollection add:verticalCollection2];
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
[self.surface.xAxes add:xAxis];
[self.surface.yAxes add:yAxis];
[self.surface.renderableSeries add:columnCollection];
[self.surface.chartModifiers addAll:[SCIZoomExtentsModifier new], [SCIRolloverModifier new], nil];
}];
}
- (SCIStackedColumnRenderableSeries *)getRenderableSeriesWithDataSeries:(SCIXyDataSeries *)dataSeries FillColor:(unsigned int)fillColor {
SCIStackedColumnRenderableSeries *rSeries = [SCIStackedColumnRenderableSeries new];
rSeries.dataSeries = dataSeries;
rSeries.fillBrushStyle = [[SCISolidBrushStyle alloc] initWithColorCode:fillColor];
rSeries.strokeStyle = [[SCISolidPenStyle alloc] initWithColorCode:fillColor thickness:1.0];
[SCIAnimations waveSeries:rSeries duration:3.0 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
//
// StackedColumnChartView.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 StackedColumnChartView: SCDSingleChartViewController<SCIChartSurface> {
override var associatedType: AnyClass { return SCIChartSurface.self }
override func initExample() {
let porkData = [10, 13, 7, 16, 4, 6, 20, 14, 16, 10, 24, 11]
let vealData = [12, 17, 21, 15, 19, 18, 13, 21, 22, 20, 5, 10]
let tomatoesData = [7, 30, 27, 24, 21, 15, 17, 26, 22, 28, 21, 22]
let cucumberData = [16, 10, 9, 8, 22, 14, 12, 27, 25, 23, 17, 17]
let pepperData = [7, 24, 21, 11, 19, 17, 14, 27, 26, 22, 28, 16]
let ds1 = SCIXyDataSeries(xType: .double, yType: .double)
ds1.seriesName = "Pork Series"
let ds2 = SCIXyDataSeries(xType: .double, yType: .double)
ds2.seriesName = "Veal Series"
let ds3 = SCIXyDataSeries(xType: .double, yType: .double)
ds3.seriesName = "Tomato Series"
let ds4 = SCIXyDataSeries(xType: .double, yType: .double)
ds4.seriesName = "Cucumber Series"
let ds5 = SCIXyDataSeries(xType: .double, yType: .double)
ds5.seriesName = "Pepper Series"
let data = 1992
for i in 0 ..< porkData.count {
let xValue = data + i;
ds1.append(x: xValue, y: porkData[i])
ds2.append(x: xValue, y: vealData[i])
ds3.append(x: xValue, y: tomatoesData[i])
ds4.append(x: xValue, y: cucumberData[i])
ds5.append(x: xValue, y: pepperData[i])
}
let verticalCollection1 = SCIVerticallyStackedColumnsCollection()
verticalCollection1.add(getRenderableSeriesWith(dataSeries: ds1, fillColor: 0xff226fb7))
verticalCollection1.add(getRenderableSeriesWith(dataSeries: ds2, fillColor: 0xffff9a2e))
let verticalCollection2 = SCIVerticallyStackedColumnsCollection()
verticalCollection2.add(getRenderableSeriesWith(dataSeries: ds3, fillColor: 0xffdc443f))
verticalCollection2.add(getRenderableSeriesWith(dataSeries: ds4, fillColor: 0xffaad34f))
verticalCollection2.add(getRenderableSeriesWith(dataSeries: ds5, fillColor: 0xff8562b4))
let columnCollection = SCIHorizontallyStackedColumnsCollection()
columnCollection.add(verticalCollection1)
columnCollection.add(verticalCollection2)
SCIUpdateSuspender.usingWith(surface) {
self.surface.xAxes.add(SCINumericAxis())
self.surface.yAxes.add(SCINumericAxis())
self.surface.renderableSeries.add(columnCollection)
self.surface.chartModifiers.add(items: SCIZoomExtentsModifier(), SCIRolloverModifier())
}
}
fileprivate func getRenderableSeriesWith(dataSeries: SCIXyDataSeries, fillColor: UInt32) -> SCIStackedColumnRenderableSeries {
let rSeries = SCIStackedColumnRenderableSeries()
rSeries.dataSeries = dataSeries
rSeries.fillBrushStyle = SCISolidBrushStyle(colorCode: fillColor)
rSeries.strokeStyle = SCISolidPenStyle(colorCode: fillColor, thickness: 1.0)
SCIAnimations.wave(rSeries, duration: 3.0, andEasingFunction: SCICubicEase())
return rSeries
}
}