custom pie charts

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,

i learned how to make simple pie charts using code like the following from
an article referenced at the end of post:

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


how would i put the values inside each pie section?


thanks,
rodchar

http://www.dotnetbips.com/articles/0e826454-619f-41de-8532-c855679031ff.aspx
 
Do you mean "how would I put the values as text inside each pie section?" If
so...

You need to define the business rules first.

You would have to determine how to orient the text. Since you're drawing
inside a wedge of a circle, you need to establish the rules for the
placement of the text. For example, you could draw the text all facing in
the same direction (as usual, horizontally), or you could draw it at an
angle projecting from the center of the circle. There are other ways I can
imagine as well.

Next, you have to define the business rules regarding how to handle text
that is too large to fit inside a single wedge. Should it begin inside the
wedge and continue outside the wedge, begin outside the wedge and finish
inside the wedge, or be centered at some point inside the wedge and extend
beyond in both directions if necessary?

Next, you have to define the business rules regarding overlapping labels.
How do you handle it if, using your other rules, the labels will overlap?
How will you displace or resize the labels?

After that it's a fairly simple matter of applying the business rules in
your code, using some geometric math to determine the starting point for
each label, the Graphics.MeasureString method to determine the sizes of the
labels, and some Matrix math (if necessary) to rotate them.

Bob Powell has an excellent site that explains the various drawing
mechanisms you need. See

http://www.bobpowell.net/faqmain.htm

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
I appreciate it Kevin, thank you.
Rod.

Kevin Spencer said:
Do you mean "how would I put the values as text inside each pie section?" If
so...

You need to define the business rules first.

You would have to determine how to orient the text. Since you're drawing
inside a wedge of a circle, you need to establish the rules for the
placement of the text. For example, you could draw the text all facing in
the same direction (as usual, horizontally), or you could draw it at an
angle projecting from the center of the circle. There are other ways I can
imagine as well.

Next, you have to define the business rules regarding how to handle text
that is too large to fit inside a single wedge. Should it begin inside the
wedge and continue outside the wedge, begin outside the wedge and finish
inside the wedge, or be centered at some point inside the wedge and extend
beyond in both directions if necessary?

Next, you have to define the business rules regarding overlapping labels.
How do you handle it if, using your other rules, the labels will overlap?
How will you displace or resize the labels?

After that it's a fairly simple matter of applying the business rules in
your code, using some geometric math to determine the starting point for
each label, the Graphics.MeasureString method to determine the sizes of the
labels, and some Matrix math (if necessary) to rotate them.

Bob Powell has an excellent site that explains the various drawing
mechanisms you need. See

http://www.bobpowell.net/faqmain.htm

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
hey all,

i learned how to make simple pie charts using code like the following from
an article referenced at the end of post:

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

how would i put the values inside each pie section?

thanks,
rodchar

http://www.dotnetbips.com/articles/0e826454-619f-41de-8532-c855679031ff.aspx

You can also use a free library like ZedGraph to draw your graphs ...
someone has already gone to the trouble of solving such problems
 
Back
Top