Solved

Pie Charts

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query issue 13 405
Consuming Server Sent Event (DOM events) in Delphi 1 793
Delphi 2010 auto upgrade has "lost" a file 7 1,088
Lazarus: saving BLOBs from Sybase database 3 161
Original post  on Monitis Blog. Web performance monitoring is broken into two camps: passive and active. Passive monitoring is defined as looking at real-world historical performance by monitoring actual log-ins, site hits, clicks, requests for…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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