<%@ Page Language="vb" AutoEventWireup="false" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language="vbscript" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim bm As New Bitmap(600, 200)
Dim g As Graphics
g = Graphics.FromImage(bm)
g.Clear(Color.Snow)
g.DrawString("Grafico a torta", New Font("Verdana", 14), Brushes.Black, New PointF(4, 4))
Dim symbolLeg As PointF = New PointF(300, 20)
Dim descLeg As PointF = New PointF(320, 16)
For i = 0 To xaxis.Length - 1
g.FillRectangle(New SolidBrush(GetColor(i)), symbolLeg.X, symbolLeg.Y, 20, 10)
g.DrawRectangle(Pens.Black, symbolLeg.X, symbolLeg.Y, 20, 10)
g.DrawString(xaxis(i).ToString, New Font("Verdana", 10), Brushes.Black, descLeg)
symbolLeg.Y += 15
descLeg.Y += 15
Next i
Dim totalAng As Integer
Dim currentangle As Single = 0
Dim startangle As Single = 0
For i = 0 To yaxis.Length - 1
totalAng = totalAng + yaxis(i)
Next
For i = 0 To yaxis.Length - 1
currentangle = yaxis(i) / totalAng * 360
g.FillPie(New SolidBrush(GetColor(i)), 100, 40, 150, 150, startangle, currentangle)
g.DrawPie(Pens.Black, 100, 40, 150, 150, startangle, currentangle)
startangle += currentangle
Next i
Dim p As New Pen(Color.Black, 2)
g.DrawRectangle(p, 1, 1, 398, 198)
bm.Save(Response.OutputStream, ImageFormat.Jpeg)
End Sub
Private Function GetColor(ByVal itemIndex As Integer) As Color
Dim objColor As Color
Select Case itemIndex
Case 0
objColor = Color.Blue
Case 1
objColor = Color.Red
Case 2
objColor = Color.Yellow
Case 3
objColor = Color.Peru
Case 4
objColor = Color.Orange
Case 5
objColor = Color.Coral
Case 6
objColor = Color.Gray
Case 7
objColor = Color.Maroon
Case Else
objColor = Color.Green
End Select
Return objColor
End Function
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
</form>
</body>
</HTML>