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 an iOS bubble chart in code. See Documentation on how to use this type here: The iOS Bubble Chart Documentation.
iOS Bubble charts can be used to visualize multi-dimensional data on a 2D Chart, for example, using the Bubble size (Z property) and color can denote data of increasing importance or weight at an X-Y location.
The SCIFastBubbleRenderableSeries requires a SCIXyzDataSeries, which contains one Z-value per X-Y point. Bubble sizes can be scaled using the SCIBubbleSeriesStyle.zScaleFactor property.
The Swift and Objective-C source code for the iOS and macOS Bubble 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
//
// BubbleChartView.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 "BubbleChartView.h"
#import "SCDDataManager.h"
#import "SCDTradeData.h"
@implementation BubbleChartView
- (void)initExample {
id<ISCIAxis> xAxis = [SCIDateAxis new];
xAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.0 max:0.1];
id<ISCIAxis> yAxis = [SCINumericAxis new];
yAxis.growBy = [[SCIDoubleRange alloc] initWithMin:0.0 max:0.1];
SCIXyzDataSeries *dataSeries = [[SCIXyzDataSeries alloc] initWithXType:SCIDataType_Date yType:SCIDataType_Double zType:SCIDataType_Double];
NSArray *tradeTicks = [SCDDataManager getTradeTicks];
for (NSUInteger i = 0, count = tradeTicks.count; i < count; i++) {
SCDTradeData *tradeData = (SCDTradeData *)tradeTicks[i];
[dataSeries appendX:tradeData.tradeDate y:tradeData.tradePrice z:tradeData.tradeSize];
}
self.rSeries = [SCIFastBubbleRenderableSeries new];
self.rSeries.bubbleBrushStyle = [[SCISolidBrushStyle alloc] initWithColorCode:0x50CCCCCC];
self.rSeries.strokeStyle = [[SCISolidPenStyle alloc] initWithColorCode:0xFFCCCCCC thickness:3.0];
self.rSeries.autoZRange = NO;
self.rSeries.dataSeries = dataSeries;
SCIFastLineRenderableSeries *lineSeries = [SCIFastLineRenderableSeries new];
lineSeries.dataSeries = dataSeries;
lineSeries.strokeStyle = [[SCISolidPenStyle alloc] initWithColorCode:0xffff3333 thickness:2.0];
[SCIUpdateSuspender usingWithSuspendable:self.surface withBlock:^{
[self.surface.xAxes add:xAxis];
[self.surface.yAxes add:yAxis];
[self.surface.renderableSeries add:lineSeries];
[self.surface.renderableSeries add:self.rSeries];
[self.surface.chartModifiers addAll:[SCIZoomExtentsModifier new], [SCIRubberBandXyZoomModifier new], nil];
[SCIAnimations scaleSeries:self.rSeries withZeroLine:10600 duration:3.0 andEasingFunction:[SCIElasticEase new]];
[SCIAnimations scaleSeries:lineSeries withZeroLine:10600 duration:3.0 andEasingFunction:[SCIElasticEase new]];
}];
}
@end
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2019. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// BubbleChartView.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 BubbleChartView: SCDBubbleChartViewControllerBase {
override func initExample() {
let xAxis = SCIDateAxis()
xAxis.growBy = SCIDoubleRange(min: 0, max: 0.1)
let yAxis = SCINumericAxis()
yAxis.growBy = SCIDoubleRange(min: 0, max: 0.1)
let dataSeries = SCIXyzDataSeries(xType: .date, yType: .double, zType: .double)
let tradeTicks = SCDDataManager.getTradeTicks()
for i in 0 ..< tradeTicks.count {
let tradeData = tradeTicks[i]
dataSeries.append(x: tradeData.tradeDate, y: tradeData.tradePrice.doubleValue, z: tradeData.tradeSize.doubleValue)
}
rSeries = SCIFastBubbleRenderableSeries();
rSeries.bubbleBrushStyle = SCISolidBrushStyle(color: 0x50CCCCCC)
rSeries.strokeStyle = SCISolidPenStyle(color: 0xFFCCCCCC, thickness: 3.0)
rSeries.autoZRange = false
rSeries.dataSeries = dataSeries
let lineSeries = SCIFastLineRenderableSeries()
lineSeries.dataSeries = dataSeries
lineSeries.strokeStyle = SCISolidPenStyle(color: 0xffff3333, thickness: 2.0)
SCIUpdateSuspender.usingWith(surface) {
self.surface.xAxes.add(xAxis)
self.surface.yAxes.add(yAxis)
self.surface.renderableSeries.add(lineSeries)
self.surface.renderableSeries.add(self.rSeries)
self.surface.chartModifiers.add(items: SCIZoomExtentsModifier(), SCIRubberBandXyZoomModifier())
SCIAnimations.scale(self.rSeries, withZeroLine: 10600.0, duration: 3.0, andEasingFunction: SCIElasticEase())
SCIAnimations.scale(lineSeries, withZeroLine: 10600.0, duration: 3.0, andEasingFunction: SCIElasticEase())
}
}
}
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2020. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// SCDBubbleChartViewControllerBase.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 "SCDBubbleChartViewControllerBase.h"
#import "SCDSettingsPresenter.h"
#import "SCDToolbarButtonsGroup.h"
#import "SCDToolbarItem.h"
#import "SCDConstants.h"
#import "SCDLabeledSettingsItem.h"
#import "SCDToolbarSliderItem.h"
@implementation SCDBubbleChartViewControllerBase {
SCDSettingsPresenter *_settingsPresenter;
}
- (Class)associatedType { return SCIChartSurface.class; }
- (NSArray<id<ISCDToolbarItem>> *)provideExampleSpecificToolbarItems {
__weak typeof(self) wSelf = self;
SCDToolbarButtonsGroup *settingsToolbar = [[SCDToolbarButtonsGroup alloc] initWithToolbarItems:@[
[[SCDToolbarItem alloc] initWithTitle:@"Bubble settings" image:[SCIImage imageNamed:@"chart.settings"] andAction:^{ [wSelf p_SCD_openSettings]; }]
]];
settingsToolbar.identifier = TOOLBAR_MODIFIERS_SETTINGS;
return @[settingsToolbar];
}
- (void)p_SCD_openSettings {
_settingsPresenter = [[SCDSettingsPresenter alloc] initWithSettingsItems:[self p_SCD_createSettingsItems] andIdentifier:TOOLBAR_MODIFIERS_SETTINGS];
}
- (NSArray<id<ISCDToolbarItem>> *)p_SCD_createSettingsItems {
__weak typeof(self) wSelf = self;
SCDToolbarSliderItem *sliderItem = [[SCDToolbarSliderItem alloc] initWithSliderValue:_rSeries.zScaleFactor maxValue:1.0 andAction:^(double sliderValue) {
wSelf.rSeries.zScaleFactor = sliderValue;
}];
return @[[[SCDLabeledSettingsItem alloc] initWithLabelText:@"Change Z-Scale" item:sliderItem iOS_orientation:SCILayoutConstraintAxisVertical]];
}
@end