# custom pie charts

Discussion in 'ASP .Net' started by =?Utf-8?B?cm9kY2hhcg==?=, Apr 2, 2007.

1. ### =?Utf-8?B?cm9kY2hhcg==?=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

=?Utf-8?B?cm9kY2hhcg==?=, Apr 2, 2007

2. ### Kevin SpencerGuest

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.

"rodchar" <> wrote in message
news:...
> 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
>
>

Kevin Spencer, Apr 2, 2007

3. ### =?Utf-8?B?cm9kY2hhcg==?=Guest

I appreciate it Kevin, thank you.
Rod.

"Kevin Spencer" wrote:

> 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:
>
> "rodchar" <> wrote in message
> news:...
> > 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
> >
> >

>
>
>

=?Utf-8?B?cm9kY2hhcg==?=, Apr 3, 2007
4. ### Rad [Visual C# MVP]Guest

On Mon, 2 Apr 2007 05:56:02 -0700, rodchar wrote:

> 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
--
Bits.Bytes
http://bytes.thinkersroom.com

Rad [Visual C# MVP], Apr 3, 2007
5. ### dotNET learnerGuest

Yes, ZedGraph does excellent job for plotting pie chart and several other
types of charts.

Have a look at :

http://zedgraph.org/wiki/index.php?title=Sample_Graphs
and
http://www.codeproject.com/csharp/zedgraph.asp

"Rad [Visual C# MVP]" <> wrote in message
news:...
> On Mon, 2 Apr 2007 05:56:02 -0700, rodchar wrote:
>
>> 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
> --
> Bits.Bytes
> http://bytes.thinkersroom.com

dotNET learner, Apr 5, 2007