Pie chart demo

Image obtained by using pbm driver and then converted to png.

 1 #pragma _ipath "./"
 2 #include "plcdemos.h"
 3 
 4 static char *text[] =
 5 {
 6     "Maurice",
 7     "Geoffrey",
 8     "Alan",
 9     "Rafael",
10     "Vince"
11 };
12 
13 
14 int
15 main(int argc, char *argv[])
16 {
17     int i, j, dthet, theta0, theta1, theta;
18     PLFLT just, dx, dy;
19     static PLFLT x[500], y[500], per[5];
20 
21     per[0] = 10.;
22     per[1] = 32.;
23     per[2] = 12.;
24     per[3] = 30.;
25     per[4] = 16.;
26 
27 
28     (void) plParseOpts(&argc, argv, PL_PARSE_FULL);
29 
30 
31     plinit();
32 
33     plenv(0., 10., 0., 10., 1, -2);
34     plcol0(2);
35     theta0 = 0;
36     dthet = 1;
37     for (i = 0; i <= 4; i++) {
38 	j = 0;
39 	x[j] = 5.;
40 	y[j++] = 5.;
41 	theta1 = theta0 + 5 * per[i];
42 	if (i == 4)
43 	    theta1 = 500;
44 	for (theta = theta0; theta <= theta1; theta += dthet) {
45 	    x[j] = 5 + 3 * cos((2.*PI/500.)*theta);
46 	    y[j++] = 5 + 3 * sin((2.*PI/500.)*theta);
47 	}
48 	plcol0(i + 1);
49 	plpsty((i + 3) % 8 + 1);
50 	plfill(j, x, y);
51 	plcol0(1);
52 	plline(j, x, y);
53 	just = (2.*PI/500.)*(theta0 + theta1)/2.;
54 	dx = .25 * cos(just);
55 	dy = .25 * sin(just);
56 	if ((theta0 + theta1)  < 250 || (theta0 + theta1) > 750) 
57 	    just = 0.;
58 	else 
59 	    just = 1.;
60 
61 	plptex((x[j / 2] + dx), (y[j / 2] + dy), 1.0, 0.0, just, text[i]);
62 	theta0 = theta - dthet;
63     }
64     plfont(2);
65     plschr(0., 1.3);
66     plptex(5.0, 9.0, 1.0, 0.0, 0.5, "Percentage of Sales");
67 
68 
69     plend();
70     exit(0);
71 }

Copyright 2006 Roman Putanowicz

Email: putanowr at twins.pk.edu.pl

Last Modified: Thu, 13 Jul 2006 15:37:29 CEST

Made with PubTal 3.1.3