4 Replies - 612 Views - Last Post: 27 June 2012 - 05:47 AM Rate Topic: -----

#1 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Pie Chart

Posted 26 June 2012 - 12:57 AM

I am making a Pie Chart and I found a helpful program but I am having an error

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


Is This A Good Question/Topic? 0
  • +

Replies To: Pie Chart

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 1951
  • View blog
  • Posts: 8,680
  • Joined: 29-May 08

Re: Pie Chart

Posted 26 June 2012 - 02:06 AM

How many Colors do you have?
How many Percents do you have?
Was This Post Helpful? 0
  • +
  • -

#3 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: Pie Chart

Posted 26 June 2012 - 08:20 AM

For now I limit the color to 5 and I am just entering 5 inputs only. .

but the maximum color and input is 20

This post has been edited by k3nnt0ter0: 26 June 2012 - 09:12 AM

Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 1951
  • View blog
  • Posts: 8,680
  • Joined: 29-May 08

Re: Pie Chart

Posted 26 June 2012 - 10:15 AM

But at the moment you have more inputs than colors. See the issue?
Was This Post Helpful? 0
  • +
  • -

#5 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: Pie Chart

Posted 27 June 2012 - 05:47 AM

I get it :)))))) Thanks!!!!!

Is it possible to place a text inside the division of the pie? and how?

This post has been edited by k3nnt0ter0: 27 June 2012 - 07:54 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1