|
-
Jul 7th, 2008, 03:37 AM
#1
Thread Starter
Member
Re: VB.net Doughnut Piecharts
Hi
In this below code
I have 3 circle
the innermost circle say circle1
the 2nd inner most circle circle2
the outermost circle circle3 (just default empty circle)
whenever I draw circle2 I have to redraw circle1
whenever I draw circle3 I have to redraw both circle2 and circle1 in that order.
When I draw circle3 the problem is to retain the parts of circle2 (circle 1 is an empty circle with no pie parts)
Every time a new pie part is added to the circle2 I save it in a collection
In case of drawing circle3
I draw circle 3 first then for I redraw the circle2 by retrieving the color,start,sweep angle attributes of the circle2. After drawing circle2 I draw circle1.
But it gives an unexpected result. This functions partially.I hope the logic is right but the implementation is going wrong somewhere. Still certain part on circle1 and circle2 is overdrawn while drawing circle3.
Please let me know where Am I going wrong. I just added hardcoded it to add 1 pie part for circle2 and another pie part for circle3
Code:
Public Class Form1
Dim myPen As Pen = Pens.Brown 'New a Pen object
Dim part As DoughnutChartPart
Dim parts As DoughnutChartPartCollection
Dim g As Graphics
Dim chk As Boolean = False
Dim colors As Color
Dim startAngle As Single
Dim sweepAngle As Single
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
parts = New DoughnutChartPartCollection
g = Me.PictureBox1.CreateGraphics()
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Me.Invalidate()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
g.DrawEllipse(myPen, 50, 50, 50, 50)
g.DrawEllipse(myPen, 38, 38, 75, 75)
g.DrawEllipse(myPen, 25, 25, 100, 100)
DrawInner()
DrawOuter()
End Sub
Private Sub DrawInner()
'MessageBox.Show("Inner")
If chk = False Then
part = New DoughnutChartPart(Color.Red, 0, 45)
g.DrawPie(New Pen(Color.Red), 38, 38, 75, 75, 0, 45)
parts.Add(part)
Else
'MessageBox.Show(parts.Count.ToString)
g.DrawPie(New Pen(Control.DefaultBackColor), 38, 38, 75, 75, 0, 360.0F)
g.DrawEllipse(myPen, 38, 38, 75, 75)
For Each part In Me.parts
g.DrawPie(New Pen(part.Colour), 38, 38, 75, 75, part.Start, part.Sweep)
'MessageBox.Show(part.Colour.ToString)
' MessageBox.Show(part.Start.ToString)
'MessageBox.Show(part.Sweep.ToString)
Next
End If
g.DrawPie(New Pen(Control.DefaultBackColor), 50, 50, 50, 50, 0, 360.0F)
g.DrawEllipse(myPen, 50, 50, 50, 50)
End Sub
Private Sub DrawOuter()
' MessageBox.Show("Outer")
g.DrawPie(Pens.Black, 25, 25, 100, 100, 0, 60)
chk = True
DrawInner()
chk = False
End Sub
End Class
Public Class DoughnutChartPart
Private _colour As Color
Private _text As String
Private _value As Single
Private _start As Single
Private _sweep As Single
Public Property Colour() As Color
Get
Return Me._colour
End Get
Set(ByVal value As Color)
Me._colour = value
End Set
End Property
Public Property Text() As String
Get
Return Me._text
End Get
Set(ByVal value As String)
Me._text = value
End Set
End Property
Public Property Start() As Single
Get
Return Me._start
End Get
Set(ByVal value As Single)
If value < 0.0 Then
Me._start = 360 + value
Else
Me._start = value
End If
End Set
End Property
Public Property Sweep() As Single
Get
Return Me._sweep
End Get
Set(ByVal value As Single)
If value < 0.0 Then
Me._sweep = 360 + value
Else
Me._sweep = value
End If
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal color As Color, _
ByVal start As Single, ByVal sweep As Single)
Me._colour = color
Me._sweep = sweep
Me._start = start
End Sub
End Class
Public Class DoughnutChartPartCollection
Inherits System.Collections.ObjectModel.Collection(Of DoughnutChartPart)
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|