Xceed Chart for WinForms v4.4 Documentation
Bubble Series

Welcome to Xceed Chart for WinForms v4.4 > User Guide > Series > XY Scatter Series > Bubble Series

Bubble charts are created with an instance of the BubbleSeries object. It is derived from the XYScatterSeries base class and inherits all its functionality. The following figure represents a typical bubble chart. 



figure 1.

Creating the Bubble Series

An instance of the BubbleSeries class can be obtained from the SeriesCollection.Add method. The method will add the newly created series to the series collection and return a reference to it. If users want to save the reference for further use, they must explicitly cast it to the BubbleSeries type. The following code will create a BubbleSeries object in the series collection and save the returned reference:

VB.NET  

' there is one chart created by default

Dim chart As Chart = CType(chartControl1.Charts(0), Chart)

 

' add a bubble series to it

Dim bubble As BubbleSeries = CType(chart.Series.Add(SeriesType.Bubble), BubbleSeries)

C#  

// there is one chart created by default

Chart chart = (Chart)chartControl1.Charts[0];

 

// add a bubble series to it

BubbleSeries bubble = (BubbleSeries)chart.Series.Add(SeriesType.Bubble);

Passing Data to the Bubble Series

Once the bubble series is created, you can add data to it. Bubble series use the Values data series of the Series class for the bubble's Y-position and the XValues data series of XYScatterSeries for the bubble's X-position. The helper methods provided by the Series and XYScatterSeries classes can be used to insert values into the data series that will be used. 

In addition to the standard Values and XValues data series, the bubble series also adds another data series of type Double, which holds the bubble sizes. It is accessible through the Sizes property of BubbleSeries object. 

In addition to the standard helper methods for feeding data that are inherited from the Series class (see the One Value Series Functionality topic) and the XYScatterSeries class (see the XY Scatter Series Functionality topic), the BubbleSeries implements the following routines. 

void AddBubble(double y, double x, double size)
- adds a bubble with XY coordinates and size

void AddBubble(double y, double x, double size, string label)
- adds a bubble with with XY coordinates, size and label

void AddBubble(double y, double x, double size, string label, FillEffect bubbleFE)
- adds a bubble with with XY coordinates, size, label and fill effect

void AddBubble(double y, double x, double size, string label, FillEffect bubbleFE, LineProperties bubbleBorder)
- adds a bubble with XY coordinates, size, label, fill effect and border properties 

For example, you can add data to a simple bubble chart with the following code:

VB.NET  

bubble.AddBubble(10, 10, 1)

bubble.AddBubble(20, 30, 2)

bubble.AddBubble(0, 0, 3)

C#  

bubble.AddBubble(10, 10, 1);

bubble.AddBubble(20, 30, 2);

bubble.AddBubble(0, 0, 3);

A labeled bubble can be created like this:

VB.NET  

bubble.AddBubble(10, 10, 1, "Company1")

bubble.AddBubble(20, 30, 2, "Company2")

bubble.AddBubble(0, 0, 3, "Company3")

 

' show only the labels in the data labels

bubble.DataLabels.Mode = DataLabelsMode.Every

bubble.DataLabels.Format = "<label>"

C#  

bubble.AddBubble(10, 10, 1, "Company1");

bubble.AddBubble(20, 30, 2, "Company2");

bubble.AddBubble(0, 0, 3, "Company3");

 

// show only the labels in the data labels

bubble.DataLabels.Mode = DataLabelsMode.Every;

bubble.DataLabels.Format = "<label>";

A bubble with different fill effects is also easy to create:

VB.NET  

bubble.AddBubble(10, 10, 1, "Company1", New FillEffect(Color.Red))

bubble.AddBubble(20, 30, 2, "Company2", New FillEffect(Color.Green))

bubble.AddBubble(0, 0, 3, "Company3", New FillEffect(Color.Blue))

 

' show only the labels in the data labels

bubble.DataLabels.Mode = DataLabelsMode.Every

bubble.DataLabels.Format = "<label>"

 

' instruct the bubble to use the data point fill effects

bubble.Appearance.FillMode = AppearanceFillMode.DataPoints

C#  

bubble.AddBubble(10, 10, 1, "Company1", new FillEffect(Color.Red));

bubble.AddBubble(20, 30, 2, "Company2", new FillEffect(Color.Green));

bubble.AddBubble(0, 0, 3, "Company3", new FillEffect(Color.Blue));

 

// show only the labels in the data labels

bubble.DataLabels.Mode = DataLabelsMode.Every;

bubble.DataLabels.Format = "<label>";

 

// instruct the bubble to use the data point fill effects

bubble.Appearance.FillMode = AppearanceFillMode.DataPoints;

Controlling the Shape of the Bubbles

The shape of the bubbles can be controlled from the BubbleStyle property. It is of type PointStyle and accepts the following values (for details, see PointStyle Enumeration): 

Bar
Cylinder

Cone

InvertedCone

Pyramid

InvertedPyramid

Sphere

Ellipse

Cross

DiagonalCross

Star
 

For example, the following code will display the bubbles as spheres:

VB.NET  
bubble.BubbleStyle = PointStyle.Sphere
C#  
bubble.BubbleStyle = PointStyle.Sphere;

Controlling the Appearance of the Bubbles

By default, all bubbles are displayed with the filling specified by the FillEffect object accessible through the BubbleFillEffect property and the border specified by the LineProperties object accessible through the BubbleBorder property. The following example displays all bubbles in green with a blue border:

VB.NET  

bubble.BubbleFillEffect.SetSolidColor(Color.Green)

bar.BubbleBorder.Color = Color.Blue

C#  

bubble.BubbleFillEffect.SetSolidColor(Color.Green);

bar.BubbleBorder.Color = Color.Blue;

Please refer to the Series Appearance topic, which describes how to apply individual fillings and lines to the series data points.

Controlling the Size of the Bubbles

The user can specify the size with which the smallest and largest bubbles are displayed with the MinSize and MaxSize properties. By default they are set to 2.5f and 12.5f Model units, respectively. The following code will increase the size of all bubbles by 1 Model unit:

VB.NET  

bubble.MinSize = 3.5F

bubble.MaxSize = 13.5F

C#  

bubble.MinSize = 3.5f;

bubble.MaxSize = 13.5f;

Bubble Series Formatting Commands

The BubbleSeries class extends the formatting command set inherited from the XYScatterSeries base class with the following formatting commands:

<size> - The current data point bubble size (extracted from the Sizes data series).

The following code displays the bubble sizes in the legend:

VB.NET  

bubble.Legend.Mode = SeriesLegendMode.DataPoints

bubble.Legend.Format = "<size>"

C#  

bubble.Legend.Mode = SeriesLegendMode.DataPoints;

bubble.Legend.Format = "<size>";

Z-Order Considerations

The Ellipse, Cross, DiagonalCross, and Star styles display bubbles that do not have a depth dimension. This makes it possible for the Xceed Chart component to apply Z-order on them so that the larger bubbles never overlap the smaller ones. If your bubble chart is likely to have overlapped bubbles, it is recommended to use these bubble styles.

Related Examples

Windows Forms: Series\Bubble\Standard Bubble

See Also

BubbleSeries