Public Class frmPieChart

  Private Sub btnDisplay_Click(ByVal sender As System.Object,
                               ByVal e As System.EventArgs) Handles btnDisplay.Click
    Dim legend() As String = {"Federal", "State", "Local"}
    Dim quantity() As Single = {33, 207, 180}
    Dim percent(quantity.Count - 1) As Single
    Dim sumOfQuantities As Single = 0
    Dim sumOfSweepAngles As Single = 0
    Dim br() As Brush = {Brushes.Blue, Brushes.Red, Brushes.Tan,
                         Brushes.Green, Brushes.Orange, Brushes.Gray}
    Dim gr As Graphics = picOutput.CreateGraphics
    'The picture box has width 312 and height 215
    Dim r As Integer = 100    'Radius of circle
    Dim c As Integer = 105    'Center of circle is (c, c)
    Me.Text = "Financing for Public Schools (K - 12)"
    'Sum the numbers for the quantities
    For i As Integer = 0 To quantity.Count - 1
      sumOfQuantities += quantity(i)
    Next
    'Convert tbe quantities to percents
    For i As Integer = 0 To quantity.Count - 1
      percent(i) = quantity(i) / sumOfQuantities
    Next
    'Display the pie chart and the legends
    For i As Integer = 0 To quantity.Count - 1
      gr.FillPie(br(i), c - r, c - r, 2 * r, 2 * r,
                 sumOfSweepAngles, percent(i) * 360)
      sumOfSweepAngles += percent(i) * 360
      'Display small colored square and legend
      gr.FillRectangle(br(i), 220, 20 + 30 * i, 20, 20)
      gr.DrawString(legend(i), Me.Font, Brushes.Black, 250, 22 + 30 * i)
    Next
  End Sub

End Class
