Solved

Pie Charts

Posted on 1997-11-05
2
1,345 Views
Last Modified: 2012-08-13
My Problem:

I have a array of 6 integers: 18,67,12,25,21,50

These six numbers need to be converted into percentages and displayed in a pie chart.

As the pie chart has 360 degrees, if I have been told correctly, to convert each number into a percentage of the pie chart, I need to times it by .36

The problem that I am having is in making the pie chart, the data is kept in an array of integers called MDATA The following is what I have of the code so far, which I think is correct...




Procedure Pie_chart;

     CLEARDEVICE;
     for H:= 1 to 6 do
     begin
     setcolor(magenta);
     setlinestyle(0,0,1);
     SetFillStyle(1, H);

     StAngle  :=          ?????????
     EndAngle :=          ?????????

     PieSlice(getmaxx div 2, getmaxy div 2, stangle, endangle, 150);

     while readkey <> chr(13) do;
     end;
     outtextxy(30,getmaxy-30,'Press Enter to end;');
     while readkey <> chr(13) do;
end;


as far as I can tell, the ???'s need to have some code to make the pie slice draw properly, but I cant work out exactly what goes there.

Any help would be greatly appreicated, thankyou.
0
Comment
Question by:xizor
2 Comments
 
LVL 2

Accepted Solution

by:
wpinto earned 30 total points
ID: 1216513
Hi xizor,

Try the following

Add all the nos
total = 18 + 67 + 12 + 25 + 21 + 50 = 193

then translate all the nos into percentages
18 = (18*100)/193 = 9.33%
67 = (67*100)/193 = 34.72%
...

Now translate these percentages into angle for drawing on the pie chart
9.33% = (9.33*360)/100 = 33.58 degrees
34.72% = (34.72*360)/100 = 125 degrees
...

Calculating the start angle & end angle is now simple
for 18, stangle = 0, endangle = 33.58
for 67, stangle = 33.58, endangle = 33.58 + 125 = 158.58
...

Note that you may need to use SetFillStyle or SetFillPattern to change the color of each slice in order to distinguish ot from its neighbour

Hope this helps

Wilfred

0
 
LVL 2

Author Comment

by:xizor
ID: 1216514
Thanks heaps thats great!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A safe way to clean winsxs folder from your windows server 2008 R2 editions
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now