Click here to Skip to main content
Licence CPOL
First Posted 13 Nov 2001
Views 141,037
Downloads 405
Bookmarked 54 times

Real Time 2D Graph for CE

By | 13 Nov 2001 | Article
A 2D graph for CE. To run this application, you must have installed eMbedded Visual C++ 3.0.

Sample Image - Graph.jpg

Introduction

This article is for developing 2D Real Time Graphs. 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

B.Manivannan

Web Developer

India India

Member

I am basically from Salem, Tamilnadu, India. I have been working in Microsoft Visual C++ since October 1998. I have experienced in VC++ 6.0, eVC++ 3.0, SOCKETS, COM/DCOM. And having knowledge in MTS, COM+.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralCommercial uses Pinmemberholapepe4:07 15 Feb '10  
Questionproblem in porting wince to smdk 2410 board. Pinmemberamiya das21:36 30 Mar '08  
QuestionPort to CE 5 [modified] Pinmembertiepvv21:55 8 Apr '07  
QuestionAny MFC codes for this project? Pinmemberluckyfox21:46 16 Jun '06  
GeneralError PinmemberRequiem Sollar12:28 22 Jul '05  
QuestionHow can make exe for PcketPc Pinmembermohsen_e_k1:47 9 May '05  
AnswerRe: How can make exe for PcketPc Pinmembersudabeh1:16 15 Nov '05  
Generalcan't linking program to exe file PinsussJonathan Lau23:21 13 Apr '05  
GeneralRe: can't linking program to exe file Pinmemberprocket18:44 11 Oct '05  
GeneralRe: can't linking program to exe file Pinmembersachin00218:32 21 Jun '06  
GeneralCompile error Pinsusswhoopi7:15 22 Feb '05  
GeneralRegisterWndClass Pinmemberwheregone0:41 11 Dec '04  
GeneralError Executing Link.Exe PinmemberLili231:27 10 May '04  
GeneralRe: Error Executing Link.Exe Pinmemberccarr14:43 9 Nov '04  
GeneralRe: Error Executing Link.Exe Pinmemberxtxd200221:53 24 Jul '05  
GeneralYou got my vote........ PinmemberDarren_vms3:54 10 Feb '04  
Questioncan u help me? Pinsusspjp_eee0:01 19 Jan '04  
AnswerRe: can u help me? PinmemberDarren_vms2:35 12 Feb '04  
GeneralClistViewCtrl with different colors for rows for wince PinmemberBilal Ahmad21:09 30 Nov '03  
QuestionIs it working at all? PinmemberAnonymous1:17 11 Feb '02  
AnswerRe: Is it working at all? PinmemberStober4:46 17 Sep '03  
GeneralGraph Control PinmemberPawel Achtel15:20 13 Jan '02  
GeneralRe: Graph Control Pinmembergarkhov_major4:30 11 Mar '05  
GeneralNot run PinmemberGianfranco Zuccaro23:01 19 Dec '01  
QuestionHow about no MFC example PinmemberPaul Gibson12:36 19 Nov '01  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120528.1 | Last Updated 14 Nov 2001
Article Copyright 2001 by B.Manivannan
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid