Real Time 2D Graph

Environment: eMbedded Visual C++ 3.0, Windows 2000, Windows CE Emulator

To Run this application you must have installed eMbedded Visual C++ 3.0

This Article is mainly contributed to develop the 2D Real Time Graph. I was searching the net to develop the graph as shown above. I found that the picture control had been used to draw the graph in Microsoft Visual Studio. To Develop this application, I needed to use the Microsoft eMbedded Visual C++ 3.0.

Historically, I've shown "live" Instrument readings through the constant updating of a numerical value by using constant value array. The Graph shows the real time data from the instrument

This MECGraphCtrl is based on the bitmap repainting concept used in Mark C. Malburg. . It provides significant enhancements through the display of scaling information and plotting of double precision values. The user implementation is described below.

In the control's owner (for example dialog) insert a dummy picture control. Size the Custom Control border to be the desired size of the GraphCtrl. Name the control something that sounds technical, like "IDC_GRAPH_CUSTOM". In the property of the custom control, For class, write GRAPH_CUSTOM. This is the string for the class that should be registered in the Constructor of the Dialog class.

1. Insert the control in the owner class.

Add a member variable of type MECGraphCtrl.

class MECPerformerDlg : public CDialog
{
  // Construction
  ...
protected:
  static BOOL RegisterWndClass(HINSTANCE hInstance);
  MECGraphCtrl m_oGraphCtrl;  
}

2. Register the custom control.

BOOL MECPerformerDlg::OnInitDialog()
{
  WNDCLASS wc;
  wc.lpszClassName = _T("GRAPH_CUSTOM"); // matches class name 
  wc.hInstance = hInstance;
  wc.lpfnWndProc = ::DefWindowProc;
  //wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.hIcon = 0;
  wc.lpszMenuName = NULL;
  wc.hbrBackground = (HBRUSH) ::GetStockObject(LTGRAY_BRUSH);
  wc.style = CS_GLOBALCLASS; // To be modified
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
}

3. Create the control.

BOOL MECPerformerDlg::OnInitDialog()
{
  ...
  CRect rect;
  GetDlgItem(IDC_GRAPH_CUSTOM)->GetWindowRect(rect) ;
  ScreenToClient(rect) ;
  GetDlgItem(IDC_GRAPH_CUSTOM)->ShowWindow(SW_HIDE);

  // create the control
  m_oGraphCtrl.Create(WS_VISIBLE | WS_CHILD, rect, this) ; 
  ...
}

4. Personalize the Control

Set the vertical range, background color, grid color and plot color.

BOOL MECPerformerDlg::OnInitDialog()
{
  ...
  // determine the rectangle for the control
  CRect rect;
  GetDlgItem(IDC_GRAPH_CUSTOM)->GetWindowRect(rect) ;
  ScreenToClient(rect) ;
  GetDlgItem(IDC_GRAPH_CUSTOM)->ShowWindow(SW_HIDE);

  // create the control
  m_oGraphCtrl.Create(WS_VISIBLE | WS_CHILD, rect, this) ; 
  m_oGraphCtrl.SetXRange(0,10,2);
  m_oGraphCtrl.SetRange(0, 10, 2) ;

  m_oGraphCtrl.SetYUnits("Volume in ml") ;
  m_oGraphCtrl.SetXUnits("Time in seconds") ;
  m_oGraphCtrl.SetBackgroundColor(RGB(0, 0, 64)) ;
  m_oGraphCtrl.SetGridColor(RGB(192, 192, 255)) ;
  m_oGraphCtrl.SetPlotColor(RGB(0, 255, 0)) ;
  ...
}

5. Use the control.

Call the m_oGraphCtrl.AppendPoint(nRandomX, nRandomY); function with the the data value to be appended to the plot.

values can be modified to achieve different styles of displays.

Downloads

Download demo project - 59 Kb


Comments

  • Need help on Real Time on Windows

    Posted by Legacy on 02/07/2004 12:00am

    Originally posted by: Leslie

    Cool stuffs but how do i implement it and make it runnable on windows? Thank you.

    Reply
  • Real Time 2D Graph

    Posted by Legacy on 01/15/2004 12:00am

    Originally posted by: aaaac

    dfgdfgfdgdfg
    gcvnbvnvbc

    Reply
  • How I can remove the error "a required resource was"

    Posted by Legacy on 07/03/2003 12:00am

    Originally posted by: ashkan

    Dear Sir,
    I draw a graph in dialog with help off Scroll Bar.
    It is necessary that my graph repeated in dialog
    in other words I update my graph with time.
    But I see after a time the error "a required resource was".
    I think that I must reset dialog before draw (or clear previous graph) new graph.
    How can I do that?
    Sincerely yours
    Thanks in advance,

    Reply
  • Can I run it in PocketPC 2002?

    Posted by Legacy on 06/30/2003 12:00am

    Originally posted by: Rico

    Hi All,

    I have added the code in my program on PocketPC 2002 platform. But the application can't start (I don't see any effect).
    My question is:
    Can I use the code provided in the PocketPC 2002 platform?

    Thanks,
    Rico.

    Reply
  • plot graph

    Posted by Legacy on 03/15/2003 12:00am

    Originally posted by: prashanth

    to plot graph which supports real time values.without using any controls

    Reply
  • Static Graph

    Posted by Legacy on 09/08/2002 12:00am

    Originally posted by: Shravan

    hello

    i Want to draw a graph of 10mm/10mm which is static means same size on 14/15/17 inches /...Moniters and also which should no depend on screen resulution.


    please help me

    Reply
  • About 2D Graph

    Posted by Legacy on 04/06/2002 12:00am

    Originally posted by: naresh kumar bhutani

    the    source   coding  help  me  about  how  to  display  the    2D  Graph
    

    Reply
  • vc6.0

    Posted by Legacy on 03/18/2002 12:00am

    Originally posted by: lorry

    i use vc6.0, and i'm sure i add the code correctly into the
    
    vc6.0 . After i press the BuildExecute Button (of course there is no error !) --------------------Configuration: performer - Win32 Debug--------------------
    Compiling resources...
    Linking...

    performer.exe - 0 error(s), 0 warning(s)

    BUT there is nothing showing !!!
    the dialog doesn't show !!
    it looks like i have used the ShowWindow(SW_HIDE)
    but i swear i didn't !!

    Reply
  • Visual C++ 6

    Posted by Legacy on 12/15/2001 12:00am

    Originally posted by: Tng

    How run this code in VC++ 6.
    Thank

    Reply
  • visual c++ 5

    Posted by Legacy on 11/21/2001 12:00am

    Originally posted by: fg

    How to run this prog in visual c++ 5
    
    

    Thank

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds