[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Pie Charts

Posted on 1997-11-05
2
Medium Priority
?
1,405 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 120 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I came across an unsolved Outlook issue and here is my solution.
Tech giants such as Amazon and Google have sold Alexa and Echo to such an extent that they have become household names. And soon they are expected to be used by commoners in their homes, ordering takeout, picking out a song, answering trivia questio…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

831 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