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 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).
//******************************************************************************
// 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:0xff84BC3D edgeColor:0xff5B8829]];
[pieSeries.segmentsCollection add:[self segmentWithValue:34.4 title:@"Municipal" centerColor:0xffe04a2f edgeColor:0xffB7161B]];
[pieSeries.segmentsCollection add:[self segmentWithValue:31.6 title:@"Personal" centerColor:0xff4AB6C1 edgeColor:0xff2182AD]];
SCIDonutRenderableSeries *donutChart = [SCIDonutRenderableSeries new];
[donutChart.segmentsCollection add:[self segmentWithValue:28.8 title:@"Walking" centerColor:0xff84BC3D edgeColor:0xff5B8829]];
[donutChart.segmentsCollection add:[self segmentWithValue:5.2 title:@"Bycicle" centerColor:0xff84BC3D edgeColor:0xff5B8829]];
[donutChart.segmentsCollection add:[self segmentWithValue:12.3 title:@"Metro" centerColor:0xffe04a2f edgeColor:0xffB7161B]];
[donutChart.segmentsCollection add:[self segmentWithValue:3.5 title:@"Tram" centerColor:0xffe04a2f edgeColor:0xffB7161B]];
[donutChart.segmentsCollection add:[self segmentWithValue:5.9 title:@"Rail" centerColor:0xffe04a2f edgeColor:0xffB7161B]];
[donutChart.segmentsCollection add:[self segmentWithValue:9.7 title:@"Bus" centerColor:0xffe04a2f edgeColor:0xffB7161B]];
[donutChart.segmentsCollection add:[self segmentWithValue:3 title:@"Taxi" centerColor:0xffe04a2f edgeColor:0xffB7161B]];
[donutChart.segmentsCollection add:[self segmentWithValue:23.2 title:@"Car" centerColor:0xff4AB6C1 edgeColor:0xff2182AD]];
[donutChart.segmentsCollection add:[self segmentWithValue:3.1 title:@"Motor" centerColor:0xff4AB6C1 edgeColor:0xff2182AD]];
[donutChart.segmentsCollection add:[self segmentWithValue:5.3 title:@"Other" centerColor:0xff4AB6C1 edgeColor:0xff2182AD]];
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
//******************************************************************************
// 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: 0xff84BC3D, edgeColor: 0xff5B8829))
pieSeries.segmentsCollection.add(segmentWithValue(segmentValue: 34.4, title: "Municipal", centerColor: 0xffe04a2f, edgeColor: 0xffB7161B))
pieSeries.segmentsCollection.add(segmentWithValue(segmentValue: 31.6, title: "Personal", centerColor: 0xff4AB6C1, edgeColor: 0xff2182AD))
let donutSeries = SCIDonutRenderableSeries()
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 28.8, title: "Walking", centerColor: 0xff84BC3D, edgeColor: 0xff5B8829))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 5.2, title: "Bycicle", centerColor: 0xff84BC3D, edgeColor: 0xff5B8829))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 12.3, title: "Metro", centerColor: 0xffe04a2f, edgeColor: 0xffB7161B))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 3.5, title: "Tram", centerColor: 0xffe04a2f, edgeColor: 0xffB7161B))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 5.9, title: "Rail", centerColor: 0xffe04a2f, edgeColor: 0xffB7161B))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 9.7, title: "Bus", centerColor: 0xffe04a2f, edgeColor: 0xffB7161B))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 3, title: "Taxi", centerColor: 0xffe04a2f, edgeColor: 0xffB7161B))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 23.1, title: "Car", centerColor: 0xff4AB6C1, edgeColor: 0xff2182AD))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 3.1, title: "Motor", centerColor: 0xff4AB6C1, edgeColor: 0xff2182AD))
donutSeries.segmentsCollection.add(segmentWithValue(segmentValue: 5.3, title: "Other", centerColor: 0xff4AB6C1, edgeColor: 0xff2182AD))
let legendModifier = SCIPieChartLegendModifier()
legendModifier.sourceSeries = pieSeries;
legendModifier.margins = SCIEdgeInsets(top: 17, left: 17, bottom: 17, right: 17)
legendModifier.position = [.bottom, .centerHorizontal];
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
}
}