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: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Due to internal controls and regulations, the amount of long term archival data is increasing every year. Since magnetic tape does not need to be periodically operated or connected to a power source, there will be no data loss because of performance degradation due to the drive actuator. Read this white paper to learn about a series of tests that determined magnetic tape is a reliable long-term storage solution for up to 30 years.

Most Popular Programming Stories

More for Developers

RSS Feeds