Pie Charts

The following program uses presentation graphics to display a pie chart for monthly sales of orange juice over a year. The chart, which is shown in Figure 10.1, remains on the screen until a key is pressed.

/* PIE.C: Create sample pie chart. */

#include <conio.h>

#include <string.h>

#include <graph.h>

#include <pgchart.h>

#define MONTHS 12

typedef enum {FALSE, TRUE} boolean;

float far value[MONTHS] =

{

33.0, 27.0, 42.0, 64.0,106.0,157.0,

182.0,217.0,128.0, 62.0, 43.0, 36.0

};

char far *category[MONTHS] =

{

“Jan”, “Feb”, “Mar”, “Apr”,

“May”, “Jun”, “Jly”, “Aug”,

“Sep”, “Oct”, “Nov”, “Dec”

};

short far explode[MONTHS] = {0};

main()

{

_chartenv env;

int mode = _VRES16COLOR;

/* Set highest video mode available */

if( _setvideomode( _MAXRESMODE ) == 0 )

exit( 0 );

/* Initialize chart library and a default pie chart */

_pg_initchart();

_pg_defaultchart( &env, _PG_PIECHART, _PG_PERCENT );

/* Add titles and some chart options */

strcpy( env.maintitle.title, “Good Neighbor Grocery” );

env.maintitle.titlecolor = 6;

env.maintitle.justify = _PG_RIGHT;

strcpy( env.subtitle.title, “Orange Juice Sales” );

env.subtitle.titlecolor = 6;

env.subtitle.justify = _PG_RIGHT;

env.chartwindow.border = FALSE;

/* Parameters for call to _pg_chartpie are:

*

* env - Environment variable

* category - Category labels

* value - Data to chart

* explode - Separated pieces

* MONTHS - Number of data values

*/

if( _pg_chartpie( &env, category, value,

explode, MONTHS ) )

{

_setvideomode( _DEFAULTMODE );

_outtext( “Error: can't draw chart” );

}

else

{

_getch();

_setvideomode( _DEFAULTMODE );

}

return( 0 );

}