Bunifu Pie chart
Create beautiful pie charts for your dashboards with Bunifu Pie charts.

Overview

Bunifu Pie chart is a chart component that generates a circular statistical graphic, in which the data is divided into slices representing the numerical proportion. Each sector corresponds to a proportional portion of the total. Consider the following example that uses Bunifu Pie Chart for data visualization:

Getting Started

Getting Started With Design View

This section explains the steps required to start creating a simple pie chart:
Step 1: Drag the canvas control to the form from the toolbox.
Step 2: Access the canvas label property and add the following values in the collection editor window.
Step 3: From the toolbox, drag and drop the BunifuPieChart to the form.
Step 4: To begin, go to the pie chart property section and set the label property to, for example, Market Value of Cloud Infrastructure.
Step 5: Access BunifuPieChart's Data property and populate the double collection editor with the following values:
Step 6: On the target property of the Pie component, select bunifuCanvas1 as the target component where it will be rendered.
Step 7: Set a list of colors in the BackgroundColor/colors property to specify the back color for each sector in the pie chart. For instance, the following is a list of colors assigned to the sectors in the color collection editor.
copy the following set of colors one by one to the color editor:
    1.
    38, 68, 120
    2.
    140, 193, 104
    3.
    112, 173, 71
    4.
    68, 114, 196
    5.
    255, 192, 0
    6.
    67, 104, 43
Step 7: Advance to the canvas properties and set the value of the XAxesGridLines and YAxesGridLines properties to false. Also, set the properties ShowXAxis and ShowYAxis to false.
Step 8: Run the application.
Pie chart legends are often located on either the bottom, right or left side of the pie chart. By setting the LegendPostion property of the canvas to value right, we can place the legends to the right of the pie, rather than above it.
We can code and render a pie chart without using the design view. Here's how to do it:

Code

C#
VB
1
void renderPieChart()
2
{
3
Bunifu.Charts.WinForms.ChartTypes.BunifuPieChart bunifuPieChart = new Bunifu.Charts.WinForms.ChartTypes.BunifuPieChart();
4
/*
5
* For this example we will use random numbers
6
*/
7
var r = new Random();
8
9
/*
10
* Add your data from your source - accepts double list
11
* Below is an example from a random number
12
*/
13
List<double> data = new List<double>();
14
15
for (int i = 0; i < 5; i++)
16
{
17
data.Add(r.Next(0,50));
18
19
}
20
/*
21
* Set your data
22
*/
23
bunifuPieChart.Data = data;
24
25
/*
26
* Specify the target canvas
27
*/
28
bunifuPieChart.TargetCanvas = bunifuChartCanvas1;
29
30
/*
31
* Hide grid lines
32
*/
33
bunifuChartCanvas1.XAxesGridLines = false;
34
bunifuChartCanvas1.YAxesGridLines = false;
35
36
/*
37
* Add labels to your canvas
38
* Label count should correspond to data count for charts like Bar charts
39
*/
40
bunifuChartCanvas1.Labels = new string[] { "Label1", "Label2", "Label3", "Label4", "Label5" };
41
42
43
/*
44
* Beautify the chart by sepcifying the colors
45
* Color count should correspond to data count
46
*/
47
List<Color> bgColors = new List<Color>();
48
for (int i = 0; i < data.Count; i++)
49
{
50
bgColors.Add(Color.FromArgb(r.Next(256), r.Next(256), r.Next(256)));
51
}
52
53
bunifuPieChart.BackgroundColor = bgColors;
54
}
55
Copied!
1
Private Sub renderPieChart()
2
Dim bunifuPieChart As Bunifu.Charts.WinForms.ChartTypes.BunifuPieChart = New Bunifu.Charts.WinForms.ChartTypes.BunifuPieChart()
3
'
4
' For this example we will use random numbers
5
'
6
Dim r = New Random()
7
8
'
9
' Add your data from your source - accepts double list
10
' Below is an example from a random number
11
'
12
Dim data As List(Of Double) = New List(Of Double)()
13
14
For i As Integer = 0 To 5 - 1
15
data.Add(r.[Next](0, 50))
16
Next
17
18
'
19
' Set your data
20
'
21
bunifuPieChart.Data = data
22
23
'
24
' Specify the target canvas
25
'
26
bunifuPieChart.TargetCanvas = bunifuChartCanvas1
27
28
'
29
' Hide grid lines
30
'
31
bunifuChartCanvas1.XAxesGridLines = False
32
bunifuChartCanvas1.YAxesGridLines = False
33
34
'
35
' Add labels to your canvas
36
' Label count should correspond to data count for charts like Bar charts
37
'
38
bunifuChartCanvas1.Labels = New String() {"Label1", "Label2", "Label3", "Label4", "Label5"}
39
40
41
'
42
' Beautify the chart by sepcifying the colors
43
' Color count should correspond to data count
44
'
45
Dim bgColors As List(Of Color) = New List(Of Color)()
46
47
For i As Integer = 0 To data.Count - 1
48
bgColors.Add(Color.FromArgb(r.[Next](256), r.[Next](256), r.[Next](256)))
49
Next
50
51
bunifuPieChart.BackgroundColor = bgColors
52
End Sub
53
Copied!

Let us examine Bunifu Pie charting properties.

Data properties

1. Data

This property gets or sets a collection of values that will be visualized on the pie chart. The order in which data values are added to the property corresponds to the order in which the canvas's label values are input.
Here is an example of how to use code to populate the pie chart with data at run-time.
C#
VB.NET
1
private void Form1_Load(object sender, EventArgs e)
2
{
3
List<Double> marketShareData = new List<double>();
4
Double[] shareDataPercentage = { 34.43, 87.21, 12.65, 54.22, 21, 78 };
5
marketShareData.AddRange(shareDataPercentage);
6
bunifuPieChart1.Data = marketShareData;
7
}
Copied!
1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
2
Dim marketShareData As New List(Of Double)()
3
Dim shareDataPercentage() As Double = { 34.43, 87.21, 12.65, 54.22, 21, 78 }
4
marketShareData.AddRange(shareDataPercentage)
5
bunifuPieChart1.Data = marketShareData
6
End Sub
7
Copied!

2. TargetCanvas

This property gets or sets the canvas on which the pie chart will be displayed.
Take note of the following properties to be modified on the canvas:
a) Set the ShowXAxis and ShowYAxis to false.
b) Additionally, set the properties XAxesGridLines and YAxesGridLines to false.
c) Assign the LegendPosition property to a value that is either bottom, left, or right.

Background and Border Properties

1. BackgroundColor

This property gets or sets the pie's background color value. We can specify the colors using the Red Green Blue (RGB) color format as well as the Alpha, Red, Green, and Blue (ARGB) color values in the color collection editor. The background color of each sector is set by adding color sets to the color selection editor.
Each color set will correspond with the order of the data provides in the Data property the sector of the pie chart.
Let's provide each sector with its own background color as shown below via code:
C#
VB.NET
1
private void Form1_Load(object sender, EventArgs e)
2
{
3
List<Color> sectorColors = new List<Color>();
4
Color[] colors = new Color[6];
5
colors[0] = Color.FromArgb(112, 173, 71);
6
colors[1] = Color.FromArgb(68, 114, 196);
7
colors[2] = Color.FromArgb(255, 192, 0);
8
colors[3] = Color.FromArgb(165, 165, 165);
9
colors[4] = Color.FromArgb(132, 226, 150);
10
colors[5] = Color.FromArgb(150, 43, 4, 78);
11
sectorColors.AddRange(colors);
12
bunifuPieChart1.BackgroundColor = sectorColors;
13
}
Copied!
1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
2
Dim sectorColors As New List(Of Color)()
3
Dim colors(5) As Color
4
colors(0) = Color.FromArgb(112, 173, 71)
5
colors(1) = Color.FromArgb(68, 114, 196)
6
colors(2) = Color.FromArgb(255, 192, 0)
7
colors(3) = Color.FromArgb(165, 165, 165)
8
colors(4) = Color.FromArgb(132, 226, 150)
9
colors(5) = Color.FromArgb(150, 43, 4, 78)
10
sectorColors.AddRange(colors)
11
bunifuPieChart1.BackgroundColor = sectorColors
12
End Sub
13
Copied!

2. BorderColor

This property gets or sets a color set to a pie chart sector/slice border. The sample form illustrates a pie chart with the border color set to:
Alternatively, we can set each pie sector to have its own border color by adding additional color sets to its color collection editor.
Take note that the order in which the border colors in the color collection editor are set will correspond to the order in which the data in the Data property is defined.

3. BorderWidth

This property gets and sets an integer value that changes the width of the pie sector boundary. The greater the value, the denser the sector borders.

4. HoverBackgroundColor

This property sets a back color value to a pie chart sector/slice on which the mouse pointer is suspended.

5. HoverBorderColor

This property changes the color of the border around a pie sector that the mouse pointer is hovering over.

6. HoverBorderWidth

This property specifies an integer value that alters the boundary width of a targetted pie chart sector over which the mouse pointer is hovering.

Take Away

Bunifu pie chart is an excellent visual chart design that communicates one important fact with the fewest visual clues possible: that the circle (the "pie") reflects some sort of whole, made up of slices. Add up all the slices and you get the complete pie. Enlarge one part, and other parts will need to shrink.
It's easy to take advantage of people's inept use of pie charts. However, when used the right way, they are very powerful: they are easy to read, familiar, and pleasant to look at. Therefore, absolute care must be taken not to overload the chart with data, but to retain the salient feature of the chart readability through the use of sparse data.
Last modified 5mo ago