2D Data Visualization Class


How to Help Your Business Become an AI Early Adopter

Sample Image


CGraphView is a class that provides multiplot 2D data visualization. It is capable of simultaneous drawing for up to 32 2D plots.
CGraphView class is derived from CView MFC class and could be used as base class for different kinds of 2D data plot views. Features supported:
-Fit width, height and page
-Mouse coordinates tracing
-Interactive add, remove and edit points
-Ability to add and display interactively up to 15000 points per second (depends on the speed of the computer)

Class interface.

Class interface provides several groups of functions:

    Graphs manipulation routines:

int AddGraph(COLORREF newColor = 0, char* title = "", BOOL bInvalidate = TRUE);
Function adds new graph to the view. Returns graph index if successful or -1 if not. If bInvalidate flag is set then view will be updated.

int RemoveGraph(int index, BOOL bInvalidate = TRUE);
Function removes graph from collection.

int UpdateGraph(int index, BOOL bInvalidate = TRUE);
Function updates graph information and view, if bInvalidate flag is set. Useful after collective operations with hidden graph.

CGraphProp* GetGraph(int index);
Function returns properties for the given graph or NULL in case of error.

CGraphProp* GetFirstGraph(int* index);
CGraphProp* GetNextGraph(int* index);
These functions are used to enumerate through all existing graphs in the view.

void SetGraphFlags(DWORD new_flags, BOOL bRedraw);
DWORD GetGraphFlags();
These functions are used to get or set graph view flags. Flag value is an OR'ed combination of:

#define GRAPH_AUTOSCALE 0x00000001    // use autoscale when adding new points
#define GRAPH_SQUAREPOINTS 0x00000002 // Draw rectangles around points
#define GRAPH_SHOW_TOOLTIP 0x00000004 // Show coordinates as a ToolTip when moving mouse #define GRAPH_DRAW_AXIS 0x00000008 //Draw axis

    Points manipulation routines:

int AddPoint(int graphnum, double x, double y, BOOL bRedraw, BOOL bUpdatePView, int index = -1);
Adds (if index == -1) or inserts new point to the graph. If bRedraw set - graph will be invalidated. If bUpdatePView set - then Point View List will be updated.

int EditPoint(int graphnum, int index, double x, double y, BOOL bRedraw);
Sets new point coordinates. If bRedraw set - invalidates graph.

int RemovePoint(int graphnum, int index, BOOL bRedraw);
Removes point from graph.

void ClearGraph(int graphnum, BOOL bRedraw, BOOL bUpdatePView);
removes all points from specified graph or from all graphs if graphnum == -1.

    Axis manipulation routines.

void SetAxisProps(char* _title, char* _UOM, int _precision, BOOL bXAxis, BOOL bRedraw);
Sets properties for axis. Properties include: Axis' title (_title), unit of measurement (_UOM) and precision - number of digits after comma (_precision). bXAxis parameter specify axis to apply attributes to and could be one of the following: GRAPH_X_AXIS or GRAPH_Y_AXIS.

void FormatAxisOutput(double value, BOOL bXAxis, int format_level, CString& res_str);
Returns formatted value parameter, regarding current axis' properties and format level. Currently three levels of format information are defined:
0 - minimum information.
1 - value and unit of measurement
2 - axis' title, value and unit of measurement

Point view list routines.

void ShowPointView(BOOL bShow);
Functions shows or hides point list.

BOOL GetPointViewState();
Returns current state of point view list.

void UpdatePointView();
Updates information in the point view list.

Class creation.

There are several steps that you should do in order to use this class in your application:
1. Include all graph files (except grres.rc) into your project.
2. Open grres.rc and copy following resources into your project resources:
    IDD_GRAPHS dialog
    IDD_POINT_EDIT dialog
4. Derive your view class from CGraphView - and off we go!


Download demo project - 107 Kb

Download source - 70 Kb

Latest updates and information could be found here.


  • 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

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date