CGraph

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:

m_pGraph->PaintGraph()

CGraph public members

class CGraph
{
public:
   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);
   CGraph();
   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;
}G_FUNCTIONSTRUCT, *LPG_FUNCTIONSTRUCT;

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

Summary

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.



Downloads

Comments

  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today make data protection a must-have, as we live in a data driven society. The digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join eVault Chief Technology …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds