Solved

Pie Charts

Posted on 1997-11-05
2
1,356 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tstream to hex 1 1,701
Android Application not running 1 491
how do i create updater to My Activex application? 3 88
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 67
Knowing where your website is hosted is as important as the features you receive, the monthly fee, and the support you receive. Due diligence should be done when choosing your next hosting provider.
Read about the importance of offline branding in the digital age.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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