Virtual Developer Workshop: Containerized Development with Docker

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.


  • Where can i get the newest version?

    Posted by Legacy on 06/06/2003 07:00am

    Originally posted by: Microsand

    Where can i get the newest version?

  • Improve pan and zoom

    Posted by Legacy on 04/03/2003 08:00am

    Originally posted by:

    Add the following lines and the control is improved noticably - the mouse input is captured outside of the window.

    void CGraphPanel::OnLButtonDown(UINT nFlags, CPoint point)
    //IWH: allow mouse to leave window and still have input

    void CGraphPanel::OnLButtonUp(UINT nFlags, CPoint point)
    //IWH for mouse control outside of window
    if (GetCapture() == this)

  • Did you have following changes with the new version?

    Posted by Legacy on 07/11/2002 07:00am

    Originally posted by: chen

    Dear all,

    I used the new version of 2d Data visualisation class because it has better interface than the old ones.
    But i like the right button menu at the pointview part of the old version. I don't know why the right button menu, such as edit, delete, insert before, insert after, reflsh, copy as...be deleted at the new version? Also i need save the modified datas in the pointview as a txt file.

    Did you have any changes about these and help me realize this?

    Thanks in advance!

  • How to get a point's coordinates by using a cursor ?

    Posted by Legacy on 09/14/2000 07:00am

    Originally posted by: BerLin

    How to get a point's absolute coordinate by using a cursor (looks like a line)?
    How to get two points' releative coordinates by using two cursors ?
    How to show the absolute and releative coordinates in a moveable lable ?
    | | * ______________ |
    | . * ||Gpaph-1 ||
    | . | . || x=30.0, y=2.0||
    |. | ||dx=20.0,dy=0.5||
    | | ||______________||
    |` | | ` ` .|
    | ` | ` | ` ` |


  • Changes for large data sets

    Posted by Legacy on 02/17/2000 08:00am

    Originally posted by: Robert Bielik

    I noticed a problem when dealing with large data sets. The initialization of the List control takes
    a HUGE amount of time. Therefore I've changed the List control into being owner drawn. Then only the
    data currently visible in the list is retrieved, dynamically. Steps for this is given below:

    1. Open the IDD_GRAPHS dialog in the resource editor. Under the "More styles" properties for the
    list control, check the "Owner data" check box.

    2. Add the following line in pview.h:

    class CPointList : public CListCtrlEx
    // Construction

    [code snipped...]

    // Generated message map functions
    afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    >>>> afx_msg void OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult); // Added 000211 Robert B.

    3. Add following in pview.cpp:

    BEGIN_MESSAGE_MAP(CPointList, CListCtrlEx)
    >> ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetDispInfo) // Added 000211 Robert B

    // CPointList message handlers

    // OnGetDispInfo, added 000211 Robert B
    void CPointList::OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult)

    CGraphView* grView = parentPtr->GetMainGraphView();
    CGraphProp* grprop = grView->GetGraph(parentPtr->m_CurrentGraph);
    if (grprop != NULL)
    if (pDispInfo->item.mask & LVIF_TEXT)
    SSinglePoint ssp;
    CString str;
    // Get data
    grprop->GetPoint(pDispInfo->item.iItem, &ssp);
    case 0:
    grView->FormatAxisOutput(ssp.x, TRUE, 1, str);
    lstrcpy(pDispInfo->item.pszText, str);
    case 1:
    grView->FormatAxisOutput(ssp.y, FALSE, 1, str);
    lstrcpy(pDispInfo->item.pszText, str);
    *pResult = 0;

    4. Change CPointsView::InitListView() in pview.cpp:

    void CPointsView::InitListView()
    if (m_CurrentGraph != -1 && parentView != NULL)
    CGraphProp* grprop = parentView->GetGraph(m_CurrentGraph);
    if (grprop != NULL)

    5. Remove the code in the CPointsView::ChangePoint(...) and CPointsView::DeletePoint(...)

    void CPointsView::ChangePoint(SGraphChange* sgc)
    /* This is not needed since data is owner drawn... 000211 Robert B
    just invalidate...

    void CPointsView::DeletePoint(SGraphChange* sgc)
    /* This is not needed since data is owner drawn... 000211 Robert B
    // Just remove one from count
    m_PointList.SetItemCountEx(m_PointList.GetItemCount() - 1);

    That's it. Now, I'm not sure that all affected parts have been changed but this worked for me... ;-)

    /Robert Bielik

  • How to draw dynamic graph? Help!!!

    Posted by Legacy on 02/06/2000 08:00am

    Originally posted by: Yigal Muttath

    Can any one tell me how can i draw dynamic graph using this
    classes i.e. shift the drawing to the left after
    it got to a specific scale,when any new point is added

    this is a call to an urgent help,please!!


  • how to draw my own graph?

    Posted by Legacy on 01/14/2000 08:00am

    Originally posted by: green bird


    what to do if i want to display my own graph using some data (instead of the graphs displayed by user)? where to set the data for points? and how to set them?

    Pls help! and pls drop me a message at:


    Thank u!

  • How can I print?

    Posted by Legacy on 01/09/2000 08:00am

    Originally posted by: G�nther Abdinghoff

    It�s a very nice tool. But how can I print the graph.
    Has anyone a sample or informations how I can do it?
    Please send me a message.


  • 2D class in a dialog based application???

    Posted by Legacy on 12/11/1999 08:00am

    Originally posted by: Bobby Kennedy

    Hey there,

    I'm working on an application and want to
    incorporate the 2D Data Visualization class into it.
    Graphing is not the sole purpose of the application, just a
    feature - so I would like to be able popup up a dialog or a
    framewnd with the graph in it (based on data that I will,
    at graph creation time, pull from a database). My
    application is dialog based b/c the doc-view architecture is
    not necessary for it -- see the problem? I don't have a
    view class to derive from CGraphView.

    So I'm looking at manually creating a doc, a
    view, and a CFrameWnd (these would serve as the dialog with
    the graph in it), and then popping that up.

    Have you ever used the graph in a dialog based
    application? Is it possible? If so, how? Also, have you
    ever manually created a doc, view, and frame wnd by hand?
    If so, how do I go about it?

    Thanks a lot,

    Bobby Kennedy

  • Wow, I've been looking for something this EASY for a long time now . . .

    Posted by Legacy on 10/28/1999 07:00am

    Originally posted by: Andon M. Coleman

    Good job man :)

    This should help me a whole lot . . . Especially the ability to simply plot out the points (A lot of the other solutions I've seen were to create Lines) . . . I'm glad I don't have to fiddle around with GDI now :)

    Thanks again . . .

    Andon M. Coleman

    Lead Programmer

    Nothing, Inc.

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

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