iOS & macOS charts - Examples
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 to create an iOS Nested Pie Chart in code.
See Documentation on how to use this type here:
The iOS Pie Chart Documentation.
The SCIPieChartSurface can be used to render either Pie, Donut or Nested Pie charts in Swift or Objective-C.
Nested charts can be animated on show, have legends and support selection of segments, as well as showing and hiding of labels. Data is provided by a number of SCIPieSegments, which are stored in a SCIPieRenderableSeries.
The Swift and Objective-C source code for the iOS and macOS Nested Pie Chartexample 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).
MultiPieDonutChartView.m
View source code//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// MultiPieDonutChartView.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 "MultiPieDonutChartView.h"
@implementation MultiPieDonutChartView
- (Class)associatedType { return SCIPieChartSurface.class; }
- (BOOL)showDefaultModifiersInToolbar { return NO; };
- (void)initExample {
SCIPieRenderableSeries *pieSeries = [SCIPieRenderableSeries new];
[pieSeries.segmentsCollection add:[self segmentWithValue:34 title:@"Ecologic" centerColor:0xFF34c19c edgeColor:0xFF34c19c]];
[pieSeries.segmentsCollection add:[self segmentWithValue:34.4 title:@"Municipal" centerColor:0xFFc43360 edgeColor:0xFFc43360]];
[pieSeries.segmentsCollection add:[self segmentWithValue:31.6 title:@"Personal" centerColor:0xFF373dbc edgeColor:0xFF373dbc]];
SCIDonutRenderableSeries *donutChart = [SCIDonutRenderableSeries new];
[donutChart.segmentsCollection add:[self segmentWithValue:28.8 title:@"Walking" centerColor:0xFF34c19c edgeColor:0xFF34c19c]];
[donutChart.segmentsCollection add:[self segmentWithValue:5.2 title:@"Bycicle" centerColor:0xFF34c19c edgeColor:0xFF34c19c]];
[donutChart.segmentsCollection add:[self segmentWithValue:12.3 title:@"Metro" centerColor:0xFFc43360 edgeColor:0xFFc43360]];
[donutChart.segmentsCollection add:[self segmentWithValue:3.5 title:@"Tram" centerColor:0xFFc43360 edgeColor:0xFFc43360]];
[donutChart.segmentsCollection add:[self segmentWithValue:5.9 title:@"Rail" centerColor:0xFFc43360 edgeColor:0xFFc43360]];
[donutChart.segmentsCollection add:[self segmentWithValue:9.7 title:@"Bus" centerColor:0xFFc43360 edgeColor:0xFFc43360]];
[donutChart.segmentsCollection add:[self segmentWithValue:3 title:@"Taxi" centerColor:0xFFc43360 edgeColor:0xFFc43360]];
[donutChart.segmentsCollection add:[self segmentWithValue:23.2 title:@"Car" centerColor:0xFF373dbc edgeColor:0xFF373dbc]];
[donutChart.segmentsCollection add:[self segmentWithValue:3.1 title:@"Motor" centerColor:0xFF373dbc edgeColor:0xFF373dbc]];
[donutChart.segmentsCollection add:[self segmentWithValue:5.3 title:@"Other" centerColor:0xFF373dbc edgeColor:0xFF373dbc]];
SCIPieChartLegendModifier *legendModifier = [SCIPieChartLegendModifier new];
legendModifier.sourceSeries = pieSeries;
legendModifier.margins = (SCIEdgeInsets){.left = 17, .top = 17, .right = 17, .bottom = 17};;
legendModifier.position = SCIAlignment_Bottom | SCIAlignment_CenterHorizontal;
legendModifier.showCheckBoxes = NO;
[self.surface.renderableSeries add:pieSeries];
[self.surface.renderableSeries add:donutChart];
[self.surface.chartModifiers add:legendModifier];
[self.surface.chartModifiers add:[SCIPieChartTooltipModifier new]];
// setting scale to 0 - needed for animation
// by default scale == 1, so that when the animation starts - the pie chart might be already drawn
pieSeries.scale = 0;
[pieSeries animateWithDuration:0.7];
donutChart.scale = 0;
[donutChart animateWithDuration:0.7];
}
- (SCIPieSegment *)segmentWithValue:(double)segmentValue title:(NSString *)title centerColor:(unsigned int)centerColor edgeColor:(unsigned int)edgeColor {
SCIPieSegment *segment = [SCIPieSegment new];
segment.value = segmentValue;
segment.title = title;
segment.fillStyle = [[SCIRadialGradientBrushStyle alloc] initWithCenterColorCode:centerColor edgeColorCode:edgeColor];
return segment;
}
@end
MultiPieDonutChartView.swift
View source code//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// MultiPieDonutChartView.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 MultiPieDonutChartView: SCDSingleChartViewController<SCIPieChartSurface> {
override var associatedType: AnyClass { return SCIPieChartSurface.self }
override var showDefaultModifiersInToolbar: Bool { return false }
override func initExample() {
let pieSeries = SCIPieRenderableSeries()
pieSeries.segmentsCollection.add(segmentWithValue(segmentValue: 34, title: "Ecologic", centerColor: 0xFF34c19c, edgeColor: 0xFF34c19c))
pieSeries.segmentsCollection.add(segmentWithValue(segmentValue: 34.4, title: "Municipal", centerColor: 0xFFc43360, edgeColor: 0xFFc43360))
pieSeries.segmentsCollection.add(segmentWithValue(segmentValue: 31.6, title: "Personal", centerColor: 0xFF373dbc, edgeColor: 0xFF373dbc))
let donutSeries = SCIDonutRenderableSeries()
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 28.8, title: "Walking", centerColor: 0xFF34c19c, edgeColor: 0xFF34c19c))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 5.2, title: "Bycicle", centerColor: 0xFF34c19c, edgeColor: 0xFF34c19c))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 12.3, title: "Metro", centerColor: 0xFFc43360, edgeColor: 0xFFc43360))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 3.5, title: "Tram", centerColor: 0xFFc43360, edgeColor: 0xFFc43360))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 5.9, title: "Rail", centerColor: 0xFFc43360, edgeColor: 0xFFc43360))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 9.7, title: "Bus", centerColor: 0xFFc43360, edgeColor: 0xFFc43360))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 3, title: "Taxi", centerColor: 0xFFc43360, edgeColor: 0xFFc43360))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 23.1, title: "Car", centerColor: 0xFF373dbc, edgeColor: 0xFF373dbc))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 3.1, title: "Motor", centerColor: 0xFF373dbc, edgeColor: 0xFF373dbc))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 5.3, title: "Other", centerColor: 0xFF373dbc, edgeColor: 0xFF373dbc))
let legendModifier = SCIPieChartLegendModifier()
legendModifier.sourceSeries = pieSeries;
legendModifier.margins = SCIEdgeInsets(top: 17, left: 17, bottom: 17, right: 17)
legendModifier.position = [.bottom, .right];
legendModifier.showCheckBoxes = false
surface.renderableSeries.add(pieSeries)
surface.renderableSeries.add(donutSeries)
surface.chartModifiers.add(legendModifier)
surface.chartModifiers.add(SCIPieChartTooltipModifier())
// setting scale to 0 - needed for animation
// by default scale == 1, so that when the animation starts - the pie chart might be already drawn
pieSeries.scale = 0
pieSeries.animate(withDuration: 0.7)
donutSeries.scale = 0
donutSeries.animate(withDuration: 0.7)
}
func segmentWithValue(segmentValue: Double, title: String, centerColor: UInt32, edgeColor: UInt32) -> SCIPieSegment {
let segment = SCIPieSegment()
segment.value = segmentValue
segment.title = title
segment.fillStyle = SCIRadialGradientBrushStyle(centerColor: centerColor, edgeColor: edgeColor)
return segment
}
}
Back to iOS & macOS charts Examples


