Quote
Index was outside the bounds of the array.
It was originally consist of 3 textboxes but I change it to datagrid so that I can enter greater than 3. So I limit my input up to 20.
Public Sub DrawPieChart(ByVal percents() As Integer, ByVal colors() As Color, _
ByVal surface As Graphics, ByVal location As Point, ByVal pieSize As Size)
Dim sum As Integer = 0
For Each percent As Integer In percents
sum += percent
Next
Dim percentTotal As Integer = 0
For percent As Integer = 0 To percents.Length() - 1
surface.FillPie( _
New SolidBrush(colors(percent)), _
New Rectangle(location, pieSize), CType(percentTotal * 360 / 100, Single), _
CType(percents(percent) * 360 / 100, Single))
percentTotal += percents(percent)
Next
Return
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PictureBox1.Hide()
Dim ctr As Integer
Dim percents(20) As Integer
ctr = 0
Do While ctr < DataGridView1.RowCount - 1
percents(ctr) = DataGridView1.Item(0, ctr).Value
ctr = ctr + 1
Loop
Dim colors() As Color = {Color.Blue, Color.Green, Color.Red, Color.Coral, Color.Chocolate}
Dim graphics As Graphics = Me.CreateGraphics
Dim location As Point = New Point(200, 200)
Dim size As Size = New Size(200, 200)
DrawPieChart(percents, colors, graphics, location, size)
End Sub
This post has been edited by k3nnt0ter0: 26 June 2012 - 12:58 AM

New Topic/Question
Reply




MultiQuote




|