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: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

  • 10 Rules that Make or Break Enterprise App Development Projects In today's app-driven world, application development is a top priority. Even so, 68% of enterprise application delivery projects fail. Designing and building applications that pay for themselves and adapt to future needs is incredibly difficult. Executing one successful project is lucky, but making it a repeatable process and strategic advantage? That's where the money is. With help from our most experienced project leads and software engineers, …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds