I am able to display pie chart.My problem is i want to display text inside the pie charts as shown below.please help me....

this is my code:
Imports
System.DrawingImports
System.Drawing.ImagingPartial
Class _Default Inherits System.Web.UI.Page' Variables declaration Private myImage As Bitmap Private g As Graphics Private p() As Integer = {1000000, 600000, 2500000, 80000} Private towns() As String = {"A", "B", "C", "D"} Private myBrushes(4) As Brush
' Initialises the bitmap, graphics context and pens for drawing Private Sub initialiseGraphics() Try ' Create an in-memory bitmap where you will draw the image. ' The Bitmap is 300 pixels wide and 200 pixels high.
myImage =
New Bitmap(500, 350, PixelFormat.Format32bppRgb) ' Get the graphics context for the bitmap.g = Graphics.FromImage(myImage)
' Create the brushes for drawingcreateBrushes()
Catch ex As Exception Throw ex End Try End Sub ' Method to create brushes of specific colours Private Sub createBrushes() TrymyBrushes(0) =
New SolidBrush(Color.Red)myBrushes(1) =
New SolidBrush(Color.Blue)myBrushes(2) =
New SolidBrush(Color.Yellow)myBrushes(3) =
New SolidBrush(Color.Green) Catch ex As Exception Throw ex End Try End Sub ' Draws the piechart Private Sub drawPieChart(ByVal g As Graphics) Try ' Variables declaration Dim i As Integer Dim total As Integer Dim percentage As Double Dim angleSoFar As Double = 0.0g.DrawString(
"Total Population", New Font("Tahoma", 16), Brushes.Black, New PointF(50, 5))' Caculates the total For i = 0 To p.Length - 1
total += p(i)
Next ' Draws the pie chart For i = 0 To p.Length - 1percentage = p(i) / total * 360
g.FillPie(myBrushes(i), 20, 50, 250, 250,
CInt(angleSoFar), CInt(percentage))g.DrawString(towns(i),
New Font("Verdana", 12, FontStyle.Bold), Brushes.Black, CInt(angleSoFar), CInt(percentage))angleSoFar += percentage
' Draws the lengendg.FillRectangle(myBrushes(i), 350, 25 + (i * 50), 25, 25)
' Label the townsg.DrawString(
"Town " & towns(i), New Font("Verdana", 8, FontStyle.Bold), Brushes.Brown, 390, 25 + (i * 50) + 10) Next Catch ex As Exception Throw ex End Try End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' Initialise graphicsinitialiseGraphics()
g.Clear(Color.WhiteSmoke)
' draws the barchartdrawPieChart(g)
' Render the image to the HTML output stream.myImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
End SubEnd
Class
The output:
i want to display % values inside the pie....please help me
Replies
Know the answer? Post it — somebody with the same question will find it here.