home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc / qc25 / scatter.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-15  |  1.8 KB  |  83 lines

  1. /* SCATTER.C:  Create sample scatter diagram. */
  2.  
  3. #include <conio.h>
  4. #include <string.h>
  5. #include <graph.h>
  6. #include <pgchart.h>
  7.  
  8. #define MONTHS 12
  9. typedef enum {FALSE, TRUE} boolean;
  10.  
  11. /* Orange juice sales */
  12.  
  13. float far xvalue[MONTHS] = 
  14.    33.0, 27.0, 42.0, 64.0,106.0,157.0,
  15.   182.0,217.0,128.0, 62.0, 43.0, 36.0
  16. };
  17. /* Hot chocolate sales */
  18.  
  19. float far yvalue[MONTHS] = 
  20.   37.0, 37.0, 30.0, 19.0, 10.0,  5.0,
  21.    2.0,  1.0,  7.0, 15.0, 28.0, 39.0
  22. };
  23.  
  24. main()
  25. {
  26.   chartenv env;
  27.   int mode = _VRES16COLOR;
  28.  
  29.   /* Set highest video mode available */
  30.  
  31.   while(!_setvideomode( mode ))
  32.      mode--;
  33.   if(mode == _TEXTMONO)
  34.      return(0);
  35.  
  36.   /* Initialize chart library and default
  37.    * scatter diagram
  38.    */
  39.  
  40.   _pg_initchart();
  41.  
  42.   _pg_defaultchart( &env, _PG_SCATTERCHART,
  43.                     _PG_POINTONLY );
  44.  
  45.   /* Add titles and some chart options */
  46.  
  47.   strcpy( env.maintitle.title, "Good Neighbor Grocery" );
  48.   env.maintitle.titlecolor = 6;
  49.   env.maintitle.justify = _PG_RIGHT;
  50.   strcpy( env.subtitle.title,
  51.           "Orange Juice vs Hot Chocolate" );
  52.   env.subtitle.titlecolor = 6;
  53.   env.subtitle.justify = _PG_RIGHT;
  54.   env.yaxis.grid = TRUE;
  55.   strcpy( env.xaxis.axistitle.title,
  56.           "Orange Juice Sales" );
  57.   strcpy( env.yaxis.axistitle.title,
  58.           "Hot Chocolate Sales" );
  59.   env.chartwindow.border = FALSE;
  60.  
  61.   /* Parameters for call to _pg_chartscatter are:
  62.    *    env        - Environment variable
  63.    *    xvalue     - X-axis data
  64.    *    yvalue     - Y-axis data
  65.    *    MONTHS     - Number of data values
  66.    */
  67.  
  68.   if(_pg_chartscatter( &env, xvalue,
  69.                         yvalue, MONTHS ))
  70.   {
  71.      _setvideomode( _DEFAULTMODE );
  72.      _outtext( "Error:  can't draw chart" );
  73.   }
  74.   else
  75.   {
  76.      getch(); 
  77.      _setvideomode( _DEFAULTMODE );
  78.   }
  79.   return(0);
  80.