Heres the code for making a pie chart based on 4 numbers, which colors them randomly. lol i made this for school


vb Code:
  1. Public Class Form1
  2.     Inherits System.Windows.Forms.Form
  3. #Region " Windows Form Designer generated code "
  4.  
  5.     Public Sub New()
  6.         MyBase.New()
  7.  
  8.         'This call is required by the Windows Form Designer.
  9.         InitializeComponent()
  10.  
  11.         'Add any initialization after the InitializeComponent() call
  12.  
  13.     End Sub
  14.  
  15.     'Form overrides dispose to clean up the component list.
  16.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  17.         If disposing Then
  18.             If Not (components Is Nothing) Then
  19.                 components.Dispose()
  20.             End If
  21.         End If
  22.         MyBase.Dispose(disposing)
  23.     End Sub
  24.  
  25.     'Required by the Windows Form Designer
  26.     Private components As System.ComponentModel.IContainer
  27.  
  28.     'NOTE: The following procedure is required by the Windows Form Designer
  29.     'It can be modified using the Windows Form Designer.  
  30.     'Do not modify it using the code editor.
  31.     Friend WithEvents btnChart As System.Windows.Forms.Button
  32.     Friend WithEvents lblInfo As System.Windows.Forms.Label
  33.     Friend WithEvents tx1 As System.Windows.Forms.TextBox
  34.     Friend WithEvents tx2 As System.Windows.Forms.TextBox
  35.     Friend WithEvents tx3 As System.Windows.Forms.TextBox
  36.     Friend WithEvents tx4 As System.Windows.Forms.TextBox
  37.     Friend WithEvents lblPie As System.Windows.Forms.Label
  38.     Friend WithEvents lblPercent As System.Windows.Forms.Label
  39.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  40.         Me.btnChart = New System.Windows.Forms.Button
  41.         Me.lblInfo = New System.Windows.Forms.Label
  42.         Me.tx1 = New System.Windows.Forms.TextBox
  43.         Me.tx2 = New System.Windows.Forms.TextBox
  44.         Me.tx3 = New System.Windows.Forms.TextBox
  45.         Me.tx4 = New System.Windows.Forms.TextBox
  46.         Me.lblPie = New System.Windows.Forms.Label
  47.         Me.lblPercent = New System.Windows.Forms.Label
  48.         Me.SuspendLayout()
  49.         '
  50.         'btnChart
  51.         '
  52.         Me.btnChart.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(128, Byte), CType(128, Byte))
  53.         Me.btnChart.Location = New System.Drawing.Point(24, 104)
  54.         Me.btnChart.Name = "btnChart"
  55.         Me.btnChart.Size = New System.Drawing.Size(104, 24)
  56.         Me.btnChart.TabIndex = 0
  57.         Me.btnChart.Text = "Chart"
  58.         '
  59.         'lblInfo
  60.         '
  61.         Me.lblInfo.Location = New System.Drawing.Point(16, 24)
  62.         Me.lblInfo.Name = "lblInfo"
  63.         Me.lblInfo.Size = New System.Drawing.Size(96, 24)
  64.         Me.lblInfo.TabIndex = 1
  65.         Me.lblInfo.Text = "Enter four values:"
  66.         Me.lblInfo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
  67.         '
  68.         'tx1
  69.         '
  70.         Me.tx1.Location = New System.Drawing.Point(128, 24)
  71.         Me.tx1.Name = "tx1"
  72.         Me.tx1.Size = New System.Drawing.Size(112, 20)
  73.         Me.tx1.TabIndex = 2
  74.         Me.tx1.Text = "10"
  75.         '
  76.         'tx2
  77.         '
  78.         Me.tx2.Location = New System.Drawing.Point(248, 24)
  79.         Me.tx2.Name = "tx2"
  80.         Me.tx2.Size = New System.Drawing.Size(112, 20)
  81.         Me.tx2.TabIndex = 3
  82.         Me.tx2.Text = "20"
  83.         '
  84.         'tx3
  85.         '
  86.         Me.tx3.Location = New System.Drawing.Point(368, 24)
  87.         Me.tx3.Name = "tx3"
  88.         Me.tx3.Size = New System.Drawing.Size(112, 20)
  89.         Me.tx3.TabIndex = 4
  90.         Me.tx3.Text = "30"
  91.         '
  92.         'tx4
  93.         '
  94.         Me.tx4.Location = New System.Drawing.Point(488, 24)
  95.         Me.tx4.Name = "tx4"
  96.         Me.tx4.Size = New System.Drawing.Size(112, 20)
  97.         Me.tx4.TabIndex = 5
  98.         Me.tx4.Text = "40"
  99.         '
  100.         'lblPie
  101.         '
  102.         Me.lblPie.Location = New System.Drawing.Point(248, 80)
  103.         Me.lblPie.Name = "lblPie"
  104.         Me.lblPie.Size = New System.Drawing.Size(301, 301)
  105.         Me.lblPie.TabIndex = 6
  106.         '
  107.         'lblPercent
  108.         '
  109.         Me.lblPercent.Location = New System.Drawing.Point(128, 56)
  110.         Me.lblPercent.Name = "lblPercent"
  111.         Me.lblPercent.Size = New System.Drawing.Size(472, 16)
  112.         Me.lblPercent.TabIndex = 7
  113.         '
  114.         'Form1
  115.         '
  116.         Me.AcceptButton = Me.btnChart
  117.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  118.         Me.ClientSize = New System.Drawing.Size(616, 405)
  119.         Me.Controls.Add(Me.lblPercent)
  120.         Me.Controls.Add(Me.lblPie)
  121.         Me.Controls.Add(Me.tx4)
  122.         Me.Controls.Add(Me.tx3)
  123.         Me.Controls.Add(Me.tx2)
  124.         Me.Controls.Add(Me.tx1)
  125.         Me.Controls.Add(Me.lblInfo)
  126.         Me.Controls.Add(Me.btnChart)
  127.         Me.MaximizeBox = False
  128.         Me.MaximumSize = New System.Drawing.Size(624, 432)
  129.         Me.MinimumSize = New System.Drawing.Size(624, 432)
  130.         Me.Name = "Form1"
  131.         Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  132.         Me.Text = "Pie Chart"
  133.         Me.ResumeLayout(False)
  134.  
  135.     End Sub
  136.  
  137. #End Region
  138.     Private Sub btnChart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChart.Click
  139.         If IsNumeric(tx1.Text) = False Or IsNumeric(tx2.Text) = False Or IsNumeric(tx3.Text) = False Or IsNumeric(tx4.Text) = False Then
  140.             MessageBox.Show("Please only choose numbers", "Idiot Alert!")
  141.             Exit Sub
  142.         End If
  143.         Dim Chart As Graphics = Me.lblPie.CreateGraphics
  144.         Chart.Clear(Color.FromKnownColor(KnownColor.Control))
  145.         Dim pBlack As New Pen(Color.Black, 2)
  146.         'store brushes in an array for ease in a loop
  147.  
  148.         Dim intSum As Integer = Int(tx1.Text) + Int(tx2.Text) + Int(tx3.Text) + Int(tx4.Text)
  149.         Dim intPercent() As Decimal = {(tx1.Text / intSum), (tx2.Text / intSum), (tx3.Text / intSum), (tx4.Text / intSum)}
  150.  
  151.         lblPercent.Text = ""
  152.         Chart.DrawEllipse(pBlack, 0, 0, 300, 300)
  153.         Dim intCount As Integer
  154.         Dim intNext As Decimal = 0
  155.         Randomize()
  156.         For intCount = 0 To 3
  157.             Dim randBrush As New SolidBrush(Color.FromArgb(CType(Rnd() * 255, Byte), CType(Rnd() * 255, Byte), CType(Rnd() * 255, Byte)))
  158.             Chart.FillPie(randBrush, 0, 0, 300, 300, intNext, (intPercent(intCount) * 360))
  159.             intNext = intNext + (intPercent(intCount) * 360)
  160.             lblPercent.Text = lblPercent.Text & Math.Round(intPercent(intCount) * 100, 2) & "% " & "                            "
  161.         Next
  162.     End Sub
  163. End Class