Solved

Pie Charts

Posted on 1997-11-05
2
1,376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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