_pg_chart Functions

Description

Display single-series or multiseries charts.

#include <pgchart.h>

short __far _pg_chart( _chartenv __far *env,
char __far * __far *categories, float __far *values, short n );

short __far _pg_chartms( _chartenv __far *env,
char __far * __far *categories, float __far *values, short nseries, short n,
short arraydim, char __far * __far *serieslabels );

env Chart environment variable  
categories Array of category variables  
values Array of data values  
n Number of data values to chart  
nseries Number of series to chart  
arraydim Row dimension of data array  
serieslabels Array of labels for series  

Remarks

The _pg_chart function displays a single-series bar, column, or line chart, depending on the type specified in the chart environment variable (env).

The _pg_chartms function displays a multiseries bar, column, or line chart, depending on the type specified in the chart environment. All the series must contain the same number of data points, specified by the argument n.

The array values is a two-dimensional array containing all value data for every series to be plotted on the chart. Each column of values represents a single series. The parameter rowdim is the integer value used to dimension rows in the array declaration for values.

For example, the following code fragment declares the identifier values to be a two-dimensional floating-point array with 20 rows and 10 columns:

#define ARRAYDIM 20

float values [ARRAYDIM][10];

short rowdim = ARRAYDIM;

Note that the number of columns in the values array cannot exceed 10, the maximum number of data series on a single chart. Note also that rowdim must be greater than or equal to the argument n, and the column dimension in the array declaration must be greater than or equal to the argument nseries. If n and nseries are set to values less than the full dimensional size of the values array, only part of the data contained in values will be plotted.

The array serieslabels holds the labels used in the chart legend to identify each series.

For a discussion of the chart environment and related topics, see “Presentation-Graphics Functions”.

Return Value

The _pg_chart and _pg_chartms functions return 0 if there were no errors. A nonzero value indicates a failure.

Compatibility

Standards:None

16-Bit:DOS

32-Bit:None

See Also

_pg_analyzechart functions, _pg_defaultchart, _pg_initchart

Example

/* PGCHART.C: This example illustrates presentation-graphics support

* routines and single-series chart routines, including

* _pg_initchart _pg_defaultchart _pg_chart _pg_chartpie

*/

#include <conio.h>

#include <graph.h>

#include <string.h>

#include <stdlib.h>

#include <pgchart.h>

#define COUNTRIES 5

float __far value[COUNTRIES] = { 42.5, 14.3, 35.2, 21.3, 32.6 };

char __far *category[COUNTRIES] = { “USSR”, “France”,"USA", “UK”, “Other” };

short __far explode[COUNTRIES] = { 0, 1, 0, 1, 0 };

void main( void )

{

_chartenv env;

short mode = _VRES16COLOR;

/* Find a valid graphics mode. */

if( !_setvideomode( _MAXRESMODE ) )

exit( 1 );

_pg_initchart(); /* Initialize chart system. */

/* Single-series bar chart */

_pg_defaultchart( &env, _PG_BARCHART, _PG_PLAINBARS );

strcpy( env.maintitle.title, “Widget Production” );

_pg_chart( &env, category, value, COUNTRIES );

_getch();

_clearscreen( _GCLEARSCREEN );

/* Single-series column chart */

_pg_defaultchart( &env, _PG_COLUMNCHART, _PG_PLAINBARS );

strcpy( env.maintitle.title, “Widget Production” );

_pg_chart( &env, category, value, COUNTRIES );

_getch();

_clearscreen( _GCLEARSCREEN );

/* Pie chart */

_pg_defaultchart( &env, _PG_PIECHART, _PG_PERCENT );

strcpy( env.maintitle.title, “Widget Production” );

_pg_chartpie( &env, category, value, explode, COUNTRIES );

_getch();

_setvideomode( _DEFAULTMODE );

exit( 0 );

}