PIETEST.C

/*********************************************************************
    (c) 1984 - 2003 by Scientific Endeavors Corporation.
    All rights reserved.
    This program plots a pie chart.
*********************************************************************/
#include <graphic.h>                    /* Include all needed files */

#if TCQ                          /* Set stack for Borland (Turbo) C */
extern unsigned _stklen = 0x3000;
#endif

/* Pie slice captions */
char *caption[ ] = {
    "Payroll 15.6%", "Advertising 29.4%", "Office 10%",
    "Fixed 20%", "Profit 25%"
};

/*********************************************************************
    Main program
*********************************************************************/
void GPC_MAIN(void)
{
    float size;
    int *clr;
    float *seg;
    float *offset;
    unsigned dim;
    dim = 5;                                      
    clr = (int *)gpcalloc(dim, sizeof(int));/* Allocate array space */
    seg = (float *)gpcalloc(dim, sizeof(float));
    offset = (float *)gpcalloc(dim, sizeof(float));
    if (clr == (int *)NULL || seg == (float *)NULL ||
        offset == (float *)NULL) {
        GPC_PUTS("PIETEST: Could not allocate data arrays");
        goto EndOfApp;
    }
                                              
    /* Define pie chart parameters */
    clr[0] = -4;
    clr[1] = -1;
    clr[2] = -2;
    clr[3] = -5;
    clr[4] = -3;

    seg[0] = 15.6f;
    seg[1] = 29.4f;
    seg[2] = 10.f;
    seg[3] = 20.f;
    seg[4] = 25.f;

    offset[0] = .15f;
    offset[1] = 0.f;
    offset[2] = 0.f;
    offset[3] = 0.f;
    offset[4] = 0.f;

    size = 2.0f;
    bgnplot(1, 'g', "pie.tkf");           /* GraphiC initialization */
    startplot(WHITE);
    metricunits(0);                 /* Ensure scaling in inch units */
    /* Select fonts */
    font(2, "swiss.fnt", '\310', "triplex.fnt", '\311');  
    page(9.0f, 6.884f);               /* Size of page and plot area */
    area2d(7.6f, 5.5f);
    color(BLUE);                                    /* Blue heading */
    heading("\311Pie Chart");
    fillfont(1);
    fntchg('\310');
    /* Pie chart */
    pieplot(dim, seg, clr, offset, caption, size, 14, 0);
    endplot();                          /* GraphiC closing routines */
    stopplot();
    gpcfree((void **)&clr);                      /* Free arrays */
    gpcfree((void **)&seg);
    gpcfree((void **)&offset);
}