Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

How to make a pie chart in Visual Basic 2008

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
21,310
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Sep 17, 2009

Visual Basic 2008 - Pie Chart! Just a simple tutorial on how to draw a pie chart using graphics :)

codes:
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

Button1_Click:
Dim percents() As Integer = {TextBox1.Text, TextBox2.Text, TextBox3.Text}
Dim colors() As Color = {Color.Blue, Color.Green, Color.Red}
Dim graphics As Graphics = Me.CreateGraphics
Dim location As Point = New Point(0, 0)
Dim size As Size = New Size(200, 200)
DrawPieChart(percents, colors, graphics, location, size)

Link to this comment:

Share to:

Top Comments

  • thanks! this will help me in a new project

  • its better if you make it unlimited

see all

All Comments (39)

Sign In or Sign Up now to post a comment!
  • Great except for the awful music

  • as to the percentage in the middle of colors. could you help me please?

  • @VisualDesignFX Yes but no, I found one way which may not be the best solution but I made a text box and the text property was """, a quotation, and made the message, for example,:

    MsgBox("This is what a quotation looks like" + txtQuotation.text)

    where txtQuotation is a textbox with a quotation mark as the text field

  • Thank you very much. Using this in my project.

    You're awesome

  • Is it possbile to put a " " " (the middle one...) in a message?

  • How to show the PieChart on PictureBox?

  • somehow this code doesn't work on winform load. it only work when put in some event like button click. I'm not sure why is that but i'm still working on it.

  • maybe if i had my speakers louder I could understand what you were doing. Love the parts where you wiggle the mouse around as "look here!"

  • Do you have any tutorial on how to create bar graph where in the values are being called by a query in sql? Thanks and God Bless. :)

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more