SciChart iOS v2.x API > 2D Chart Types > The Bubble Charts Type
The Bubble Charts Type

Bubble Series are provided by the SCIFastBubbleRenderableSeries type. This accepts data from a SCIXyzDataSeries (X,Y value are position, Z is size) and renders a variable size bubble at each data-point.

Examples for the Bubble Series can be found in the SciChart iOS Examples Suite

 

 

To declare a SCIFastBubbleRenderableSeries use the following code:

 

Declare a SCIFastBubbleRenderableSeries

// Declare a new XyDataSeries with XType Float, and YType Float
SCIXyzDataSeries * dataSeries = [[SCIXyzDataSeries alloc] initWithXType:SCIDataType_Float YType:SCIDataType_Float ZType:SCIDataType_Float];
// Append some data. SCIGenericStruct converts without boxing of primitives
int dataCount = 20;
for(int i=0; i < dataCount; i++) {
    double time = 10 * i / (double)dataCount;
    double x = time;
    double y = arc4random_uniform(20);
    double size = arc4random_uniform(20);
    [dataSeries appendX:SCIGeneric(x) Y:SCIGeneric(y) Z:SCIGeneric(size)];
}

// Create a SCIBubbleRenderableSeries and apply DataSeries
SCIBubbleRenderableSeries *bubbleRenderableSeries = [[SCIBubbleRenderableSeries alloc] init];
bubbleRenderableSeries.bubbleBrushStyle = [[SCISolidBrushStyle alloc] initWithColorCode:0x50CCCCCC];
bubbleRenderableSeries.strokeStyle = [[SCISolidPenStyle alloc] initWithColorCode:0xFFCCCCCC withThickness:1.0];
bubbleRenderableSeries.style.detalization = 44;
bubbleRenderableSeries.zScaleFactor = 1.0;
bubbleRenderableSeries.autoZRange = false;
[bubbleRenderableSeries setDataSeries:dataSeries];

// Note Surface must have an XAxis/YAxis of type SCINumericAxis to match the float,float data
id<SCIAxis2DProtocol> axis = [[SCINumericAxis alloc] init];
[axis setGrowBy: [[SCIDoubleRange alloc]initWithMin:SCIGeneric(0.1) Max:SCIGeneric(0.1)]];
[_sciChartSurface.yAxes add:axis];
axis = [[SCINumericAxis alloc] init];
[axis setGrowBy: [[SCIDoubleRange alloc]initWithMin:SCIGeneric(0.1) Max:SCIGeneric(0.1)]];
[_sciChartSurface.xAxes add:axis];
// Add the Line Series to an existing SciChartSurface
[_sciChartSurface.renderableSeries add:bubbleRenderableSeries];
// Create a SCIChartSurface instance
//var sciChartSurface = SCIChartSurface(frame: frame)
// NOTE: You will need to add the SCIChartSurface as a SubView to your View
//
// Declare a new XyDataSeries with XType Float, and YType Float
let dataSeries = SCIXyzDataSeries(xType: .float, yType: .float, zType: .float)
// Append some data. SCIGenericStruct converts without boxing of primitives
let dataCount: Int = 20
for i in 0..<dataCount {
    let time = (10.0 * Double(i)) / Double(dataCount)
    let x: Double = time;
    let y: Double = Double(arc4random_uniform(20))
    let size: Double = Double(arc4random_uniform(20))
    dataSeries.appendX(SCIGeneric(x), y: SCIGeneric(y), z: SCIGeneric(size))
}
// Create a SCIBubbleRenderableSeries and apply DataSeries
var bubbleRenderableSeries = SCIBubbleRenderableSeries()
bubbleRenderableSeries.bubbleBrushStyle = SCISolidBrushStyle(colorCode: 0x50cccccc)
bubbleRenderableSeries.strokeStyle = SCISolidPenStyle(colorCode: 0xffcccccc, withThickness: 1.0)
bubbleRenderableSeries.style.detalization = 44
bubbleRenderableSeries.zScaleFactor = 1.0
bubbleRenderableSeries.autoZRange = false
bubbleRenderableSeries.dataSeries = dataSeries

// Note Surface must have an XAxis/YAxis of type SCINumericAxis to match the float,float data
let xAxis = SCINumericAxis()
xAxis.growBy = SCIDoubleRange(min: SCIGeneric(0.1), max: SCIGeneric(0.1))
sciChartSurface.yAxes.add(xAxis)
let yAxis = SCINumericAxis()
yAxis.growBy = SCIDoubleRange(min: SCIGeneric(0.1), max: SCIGeneric(0.1))
sciChartSurface.xAxes.add(yAxis)
// Add the Line Series to an existing SciChartSurface
sciChartSurface.renderableSeries.add(bubbleRenderableSeries)
// Create a SCIChartSurface instance
var sciChartSurface = new SCIChartSurface();
// NOTE: You will need to add the SCIChartSurface as a SubView to your View
//
// Declare a new XyzDataSeries with XType Float, and YType Float and ZType float
var dataSeries = new XyzDataSeries<float, float, float>();
// Append some data.
int dataCount = 20;
var random = new Random();
for (int i = 0; i < dataCount; i++)
{
    float x = 10 * i / (float)dataCount;
    float y = random.Next(0, 20);
    float size = random.Next(1, 20);
    dataSeries.Append(x, y, size);
}
// Create a SCIBubbleRenderableSeries and apply DataSeries
var bubbleRenderableSeries = new SCIBubbleRenderableSeries();
bubbleRenderableSeries.BubbleBrushStyle = new SCISolidBrushStyle(colorCode: 0x50cccccc);
bubbleRenderableSeries.StrokeStyle = new SCISolidPenStyle(colorCode: 0xffcccccc, thickness: 1.0f);
bubbleRenderableSeries.Style.Detalization = 44;
bubbleRenderableSeries.ZScaleFactor = 1.0;
bubbleRenderableSeries.AutoZRange = false;
bubbleRenderableSeries.DataSeries = dataSeries;
// Note Surface must have an XAxis/YAxis of type SCINumericAxis to match the float,float data
var xAxis = new SCINumericAxis { GrowBy = new SCIDoubleRange(0.1, 0.1) };
sciChartSurface.XAxes.Add(xAxis);
var yAxis = new SCINumericAxis { GrowBy = new SCIDoubleRange(0.1, 0.1) };
sciChartSurface.YAxes.Add(yAxis);
// Add the Line Series to an existing SciChartSurface           
sciChartSurface.RenderableSeries.Add(bubbleRenderableSeries);

 

Still stuck?

You can check the Online iOS Bubble Chart Example about using this kind of renderable series.

Also our series of Swift and Xamarin Tutorials here.