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 | |
---|---|
|
C# | |
---|---|
|
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 | |
---|---|
|
C# | |
---|---|
|
A labeled bubble can be created like this:
VB.NET | |
---|---|
|
C# | |
---|---|
|
A bubble with different fill effects is also easy to create:
VB.NET | |
---|---|
|
C# | |
---|---|
|
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 | |
---|---|
|
C# | |
---|---|
|
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 | |
---|---|
|
C# | |
---|---|
|
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 | |
---|---|
|
C# | |
---|---|
|
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