What Is CGraph?

CGraph, in its way, is like any other graph display in that it can be considered an electronic version of graph paper, allowing the graphical display of X v Y information.

What Does CGraph Look Like?

The screen cap shows a CGraph being used in a CDialogbox. CGraph has a number of pre-defined colorschemes that define colors for such items as background, grid color, graphtitle color, and so forth. Most of these items have their own access routines, so they also be set independently.

Join the Dots

CGraph plots data in three formats:

  • Dot
  • Bar chart
  • Line chart

The CGraph Class

CGraph is written in MSVC++ V6. It is not descended from a CWnd object, which means it does not get its own WM_PAINT messages—you put in a call to the CGraph's paint routine in your application's paint procedure. To use CGraph, you can embed a CGraph object in your CWnd or CDialog class, or create it on the heap by using the new operator.

CGraph needs a pointer to its holding parent window. If you use the default constructor, you have to set this window pointer in a seperate call. It is better to use the the special constructor:

CGraph(CWnd *pParentWnd,int xPos=0, int yPos=0, int Width =0,
       int Height=0, UINT colorscheme=G_DEFAULTSCHEME)

This constructor will be used like this at some approprate place in your code:

m_pGraph=new CGraph(this,0,0,0,0,G_REDSCHEME);

and in your WM_PAINT handler:


CGraph public members

class CGraph
   void ShowTicks(BOOL bShow);
   void ClearFunction(void);
   BOOL DoFunction(G_FUNCTIONSTRUCT *pFunctionParams);
   void SetFunctionName(CString FunctionName);
   void ShowGrid(BOOL bShow);
   void SetYLineAtLeft(BOOL AtLeft);
   void GraphSetAllDefaults();
   void SetYLegendText(CString YText);
   void SetXLegendText(CString XText);
   void SetGraphTitle(CString GraphTitle);
   void PaintGraph(void);
   CGraph(CWnd *pParentWnd,int xPos=0, int yPos=0, int Width =0,
          int Height=0, UINT colorscheme=G_DEFAULTSCHEME);
   void SetYAxisScale(double min, double max);
   void SetXAxisScale(double min,double max);
   void SetGraphSizePos(int xPos, int yPos, int Width, int Height);
   void SetColorScheme(int Scheme, BOOL bRedraw=FALSE);
   void CreateGraphFont(CString FaceName,UINT size);
   virtual ~CGraph();

What Functions Are Available?

CGraph has 12 functions. Some of these are mathematical; for example, there is a function y=sin(x) that displays a sine wave.

There are data functions where you, the user, have collected or calculated some data and you want it displayed on a graph. These 'user' functions are:

  • PlotXY
  • MultiPlotXY
  • Deviation Absolute
  • Deviation Percent
  • Histogram Absolute
  • Histogram percent

Function/Plot Data

All functions (and associated plot data if required) for the graph are presented by using a pointer to a G_FUNCTIONSTRUCT that is defined as follows:

typedef struct
   UINT FuncType;     //e.g. G_SINX
   UINT ChartType;    //bar, line, dot, etc..
   double xMin;
   double xMax;
   double yMin;
   double yMax;
   char   *szGraphTitle;
   char   *szYLegend;
   char   *szXLegend;
   double *pPlotXYItems;
   UINT    num_PlotXYItems;
   double  Const_1;
   double  Const_2;

Some functions require the pPlotXYItems pointer to address an array of num_PlotXyItems xy pairs of type double for plotting.


That's all for now; this typing into the tiny CG article window is taxing. I'll write this up as an HTML file and upload it. Meanwile, feel free to play with the demo and add constructive criticisms.



Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Hurricane Sandy was one of the most destructive natural disasters that the United States has ever experienced. Read this success story to learn how Datto protected its partners and their customers with proactive business continuity planning, heroic employee efforts, and the right mix of technology and support. With storm surges over 12 feet, winds that exceeded 90 mph, and a diameter spanning more than 900 miles, Sandy resulted in power outages to approximately 7.5 million people, and caused an estimated $50 …

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds