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 }
Code description
- 1
- $Id: x13c.c,v 1.15 2002/12/03 08:39:24 airwin Exp $ Pie chart demo.
- 13
- --------------------------------------------------------------------------*\ * main * * Does a simple pie chart. \*--------------------------------------------------------------------------
- 27
- Parse and process command line arguments
- 30
- Initialize plplot
- 35
- n.b. all theta quantities scaled by 2*pi/500 to be integers to avoid * floating point logic problems.
- 41
- n.b. the theta quantities multiplied by 2*pi/500 afterward so * in fact per is interpreted as a percentage.
- 68
- Don't forget to call PLEND to finish off!