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

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

Most Popular Programming Stories

More for Developers

RSS Feeds