Wednesday 7 October 2009

Pie Chart Control

I found a nice pie chart control here: www.codeproject.com/KB/graphics/julijanpiechart.aspx.

To include this in one of my own projects this is the quick start method.

Copy the PieChart.dll into the solutions folder.
Go to toolbox and browse for the dll to add it.

Drag the piechart control to a form.

There are two sets of values that must be setup, otherwise an exception occurs.
Here is a sample of the most basic code:
Dim Vals(4) As Decimal
Dim Texts(4) As String
Texts(0) = "apples"
Texts(1) = "plums"
Texts(2) = "grapes"
Texts(3) = "cherries"
Try
Vals(0) = 45
Vals(1) = 20
Vals(2) = 75
Vals(3) = 45
Me.PieChartControl1.Values = Vals
Me.PieChartControl1.Texts = Texts
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try


This produces a odd looking pie chart. For nice charts some other settings should be changed too.

Setting up displacements give a chart that looks like this:


Displacements should have values like 0.05 and o.20


SliceRelativeHeight gives depth to the chart



These are the minimum settings to create a nice 3-D pie chart.