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 100% Stacked Column chart, grouped side by side in code. 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).
The Swift 4 and Objective-C source code for the iOS Stacked Column 100% 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
//
// StackedColumnFullFillChartView.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 "StackedColumnFullFillChartView.h"
#import "SCDDataManager.h"
@implementation StackedColumnFullFillChartView
- (Class)associatedType { return SCIChartSurface.class; }
- (void)initExample {
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 *columnCollection = [SCIVerticallyStackedColumnsCollection new];
columnCollection.isOneHundredPercent = YES;
[columnCollection add:[self getRenderableSeriesWithDataSeries:ds1 fillColor:0xff226fb7]];
[columnCollection add:[self getRenderableSeriesWithDataSeries:ds2 fillColor:0xffff9a2e]];
[columnCollection add:[self getRenderableSeriesWithDataSeries:ds3 fillColor:0xffdc443f]];
[columnCollection add:[self getRenderableSeriesWithDataSeries:ds4 fillColor:0xffaad34f]];
[columnCollection add:[self getRenderableSeriesWithDataSeries:ds5 fillColor:0xff8562b4]];
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
[self.surface.xAxes add:[SCINumericAxis new]];
[self.surface.yAxes add:[SCINumericAxis new]];
[self.surface.renderableSeries add:columnCollection];
}];
}
- (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];
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
//
// StackedColumnFullFillChartView.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 StackedColumnFullFillChartView: 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 columnCollection = SCIVerticallyStackedColumnsCollection()
columnCollection.isOneHundredPercent = true
columnCollection.add(getRenderableSeriesWith(dataSeries: ds1, fillColor: 0xff226fb7))
columnCollection.add(getRenderableSeriesWith(dataSeries: ds2, fillColor: 0xffff9a2e))
columnCollection.add(getRenderableSeriesWith(dataSeries: ds3, fillColor: 0xffdc443f))
columnCollection.add(getRenderableSeriesWith(dataSeries: ds4, fillColor: 0xffaad34f))
columnCollection.add(getRenderableSeriesWith(dataSeries: ds5, fillColor: 0xff8562b4))
SCIUpdateSuspender.usingWith(surface) {
self.surface.xAxes.add(SCINumericAxis())
self.surface.yAxes.add(SCINumericAxis())
self.surface.renderableSeries.add(columnCollection)
}
}
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)
return rSeries
}
}