home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c500 / 1.ddi / SRC386.WPK / PGDEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-28  |  5.4 KB  |  192 lines

  1. #include <graph.h>
  2. #include <pgchart.h>
  3. #include <string.h>
  4. #include <conio.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8.  
  9. #if defined( __386__ )
  10.     #define _FAR
  11. #else
  12.     #define _FAR        __far
  13. #endif
  14.  
  15.  
  16. #define NUM_SERIES      2
  17. #define NUM_VALUES      4
  18.  
  19.  
  20. char _FAR               *categories[ NUM_VALUES ] = {
  21.                             "Jan", "Feb", "Mar", "Apr" };
  22. char _FAR               *labels[ NUM_SERIES ] = {
  23.                             "Apples", "Oranges" };
  24. float                   values[ NUM_SERIES ][ NUM_VALUES ] = {
  25.                             20, 45, 30, 25, 30, 25, 40, 15 };
  26. float                   x[ NUM_SERIES ][ NUM_VALUES ] = {
  27.                             5, 15, 30, 40, 10, 20, 30, 45 };
  28. float                   y[ NUM_SERIES ][ NUM_VALUES ] = {
  29.                             10, 15, 30, 45, 40, 30, 15, 5 };
  30. short                   explode[ NUM_VALUES ] = {
  31.                             1, 0, 0, 0 };
  32. struct videoconfig      vconfig;
  33. int                     xmax, ymax, xmid, ymid;
  34.  
  35.  
  36. int main( int argc, char *argv[] )
  37. //================================
  38.  
  39. //  Initialize graphics library and presentation graphics
  40. //  system and then display several sample charts.
  41.  
  42. {
  43.     int                 mode;
  44.  
  45.     if( argc == 2 ) {
  46.         mode = atoi( argv[ 1 ] );
  47.     } else {
  48.         mode = _MAXRESMODE;
  49.     }
  50.     if( _setvideomode( mode ) == 0 ) {
  51.         puts( "Cannot initialize video mode" );
  52.         return( 1 );
  53.     }
  54.     _getvideoconfig( &vconfig );
  55.     xmax = vconfig.numxpixels;
  56.     ymax = vconfig.numypixels;
  57.     xmid = xmax / 2;
  58.     ymid = ymax / 2;
  59.     _pg_initchart();
  60.     simple_chart();
  61.     press_key();
  62.     _clearscreen( _GCLEARSCREEN );
  63.     more_charts();
  64.     press_key();
  65.     _clearscreen( _GCLEARSCREEN );
  66.     scatter_charts();
  67.     press_key();
  68.     _setvideomode( _DEFAULTMODE );
  69. }
  70.  
  71.  
  72. void press_key()
  73. //==============
  74.  
  75. //  Display a message and wait for the user to press a key
  76.  
  77. {
  78.     int                 len;
  79.     char                *msg;
  80.     struct _fontinfo    info;
  81.  
  82.     _getfontinfo( &info );
  83.     msg = " Press any key ";
  84.     len = _getgtextextent( msg );
  85.     _setcolor( 4 );
  86.     _rectangle( _GFILLINTERIOR, xmax - len, 0,
  87.                                 xmax - 1, info.pixheight + 2 );
  88.     _setcolor( 15 );
  89.     _moveto( xmax - len, 1 );
  90.     _outgtext( msg );
  91.     getch();
  92. }
  93.  
  94.  
  95. void simple_chart()
  96. //=================
  97.  
  98. //  Display a simple column chart
  99.  
  100. {
  101.     chartenv            env;
  102.  
  103.     _pg_defaultchart( &env, _PG_COLUMNCHART, _PG_PLAINBARS );
  104.     strcpy( env.maintitle.title, "Column Chart" );
  105.     _pg_chart( &env, categories, values, NUM_VALUES );
  106. }
  107.  
  108.  
  109. void more_charts()
  110. //================
  111.  
  112. //  Display several sample charts on different areas of the screen
  113.  
  114. {
  115.     chartenv            env;
  116.  
  117.     // use only left half of screen
  118.     _pg_defaultchart( &env, _PG_COLUMNCHART, _PG_PLAINBARS );
  119.     strcpy( env.maintitle.title, "Column Chart" );
  120.     env.chartwindow.x1 = 0;
  121.     env.chartwindow.y1 = 0;
  122.     env.chartwindow.x2 = xmid - 1;
  123.     env.chartwindow.y2 = ymax - 1;
  124.     _pg_chart( &env, categories, values, NUM_VALUES );
  125.  
  126.     // use top right corner
  127.     _pg_defaultchart( &env, _PG_BARCHART, _PG_PLAINBARS );
  128.     strcpy( env.maintitle.title, "Bar Chart" );
  129.     env.chartwindow.x1 = xmid;
  130.     env.chartwindow.y1 = 0;
  131.     env.chartwindow.x2 = xmax - 1;
  132.     env.chartwindow.y2 = ymid - 1;
  133.     env.legend.place = _PG_BOTTOM;
  134.     _pg_chartms( &env, categories, values, NUM_SERIES,
  135.                  NUM_VALUES, NUM_VALUES, labels );
  136.  
  137.     // use lower right corner
  138.     _pg_defaultchart( &env, _PG_PIECHART, _PG_NOPERCENT );
  139.     strcpy( env.maintitle.title, "Pie Chart" );
  140.     env.chartwindow.x1 = xmid;
  141.     env.chartwindow.y1 = ymid;
  142.     env.chartwindow.x2 = xmax - 1;
  143.     env.chartwindow.y2 = ymax - 1;
  144.     _pg_chartpie( &env, categories,
  145.                   values, explode, NUM_VALUES );
  146. }
  147.  
  148.  
  149. void scatter_charts()
  150. //===================
  151.  
  152. //  Display two scatter charts beside each other;
  153. //  one using default options, the other customized
  154.  
  155. {
  156.     chartenv            env;
  157.  
  158.     // use left half of screen
  159.     _pg_defaultchart( &env, _PG_SCATTERCHART, _PG_POINTANDLINE );
  160.     strcpy( env.maintitle.title, "Scatter Chart" );
  161.     env.chartwindow.x1 = 0;
  162.     env.chartwindow.y1 = 0;
  163.     env.chartwindow.x2 = xmid - 1;
  164.     env.chartwindow.y2 = ymax - 1;
  165.     _pg_chartscatterms( &env, x, y, NUM_SERIES,
  166.                         NUM_VALUES, NUM_VALUES, labels );
  167.  
  168.     // use right half of screen
  169.     _pg_defaultchart( &env, _PG_SCATTERCHART, _PG_POINTANDLINE );
  170.     strcpy( env.maintitle.title, "Scatter Chart" );
  171.     strcpy( env.subtitle.title, "(1991 Production)" );
  172.     env.chartwindow.x1 = xmid;
  173.     env.chartwindow.y1 = 0;
  174.     env.chartwindow.x2 = xmax - 1;
  175.     env.chartwindow.y2 = ymax - 1;
  176.     env.chartwindow.background = 2;
  177.     env.datawindow.background = 8;
  178.     env.legend.legendwindow.background = 8;
  179.     env.legend.place = _PG_BOTTOM;
  180.     env.maintitle.justify = _PG_LEFT;
  181.     _pg_analyzescatterms( &env, x, y, NUM_SERIES,
  182.                         NUM_VALUES, NUM_VALUES, labels );
  183.     env.yaxis.autoscale = 0;
  184.     env.yaxis.scalemin = 0.0;
  185.     env.yaxis.scalemax = 60.0;
  186.     env.yaxis.ticinterval = 20.0;
  187.     env.yaxis.grid = 1;
  188.     env.yaxis.gridstyle = 2;
  189.     _pg_chartscatterms( &env, x, y, NUM_SERIES,
  190.                         NUM_VALUES, NUM_VALUES, labels );
  191. }
  192.