Click here to Skip to main content
15,885,365 members
Articles / Mobile Apps

Real Time 2D Graph for CE

Rate me:
Please Sign up or sign in to vote.
3.20/5 (4 votes)
13 Nov 2001CPOL1 min read 184.2K   1.4K   54   26
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)


Written By
Web Developer
India India
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+.

Comments and Discussions

 
GeneralCommercial uses Pin
holapepe15-Feb-10 4:07
holapepe15-Feb-10 4:07 
Questionproblem in porting wince to smdk 2410 board. Pin
amiya das30-Mar-08 21:36
amiya das30-Mar-08 21:36 
QuestionPort to CE 5 [modified] Pin
tiepvv8-Apr-07 21:55
tiepvv8-Apr-07 21:55 
QuestionAny MFC codes for this project? Pin
luckyfox16-Jun-06 21:46
luckyfox16-Jun-06 21:46 
GeneralError Pin
Requiem Sollar22-Jul-05 12:28
Requiem Sollar22-Jul-05 12:28 
QuestionHow can make exe for PcketPc Pin
mohsen_e_k9-May-05 1:47
mohsen_e_k9-May-05 1:47 
AnswerRe: How can make exe for PcketPc Pin
sudabeh15-Nov-05 1:16
sudabeh15-Nov-05 1:16 
Generalcan't linking program to exe file Pin
jonathan lau13-Apr-05 23:21
jonathan lau13-Apr-05 23:21 
GeneralRe: can't linking program to exe file Pin
procket11-Oct-05 18:44
procket11-Oct-05 18:44 
GeneralRe: can't linking program to exe file Pin
sachin00221-Jun-06 18:32
sachin00221-Jun-06 18:32 
GeneralCompile error Pin
abimbolacole22-Feb-05 7:15
abimbolacole22-Feb-05 7:15 
GeneralRegisterWndClass Pin
wheregone11-Dec-04 0:41
wheregone11-Dec-04 0:41 
GeneralError Executing Link.Exe Pin
Lili2310-May-04 1:27
Lili2310-May-04 1:27 
GeneralRe: Error Executing Link.Exe Pin
ccarr9-Nov-04 14:43
ccarr9-Nov-04 14:43 
GeneralRe: Error Executing Link.Exe Pin
xtxd200224-Jul-05 21:53
xtxd200224-Jul-05 21:53 
GeneralYou got my vote........ Pin
Darren_vms10-Feb-04 3:54
Darren_vms10-Feb-04 3:54 
Firstly thanks for posting your work, This sort of stuff is hard to find for pocketpc/mobile.

I have been looking over the code and succesfully got the demo app up and running. I did however have a couple of problem and I think I have corrected. Now I am not sure if it's a bug or my understanding of the code but I found that the data when displayed is expected to start low on the scale.

Taken from

void MECGraphCtrl::DrawPoints()

if(m_nLastIndexPoint == 0)
{
int nXOrigin = m_rectPlot.left ;
int nYOrigin = m_rectPlot.bottom ;
m_dcPlot.MoveTo (nXOrigin, nYOrigin) ; <- Problem Here -----

m_dPoints[m_nLastIndexPoint].x = m_rectPlot.left+(long)((m_oPoints[m_nLastIndexPoint].x - m_dXLower) * m_dHorizontalFactor) ;
m_dPoints[m_nLastIndexPoint].y = m_rectPlot.bottom -
(long)((m_oPoints[m_nLastIndexPoint].y - m_dLowerLimit) * m_dVerticalFactor) ;

m_dcPlot.LineTo ((int)m_dPoints[m_nLastIndexPoint].x, (int)m_dPoints[m_nLastIndexPoint].y) ;
}

I wanted to start at the top or middle depending on the data and found that the following correct my problem.


if(m_nLastIndexPoint == 0)
{

// remove int nXOrigin = m_rectPlot.left ;
// remove int nYOrigin = m_rectPlot.bottom ;
// remove m_dcPlot.MoveTo (nXOrigin, nYOrigin) ;

m_dPoints[m_nLastIndexPoint].x = m_rectPlot.left+(long)((m_oPoints[m_nLastIndexPoint].x - m_dXLower) * m_dHorizontalFactor) ;
m_dPoints[m_nLastIndexPoint].y = m_rectPlot.bottom -
(long)((m_oPoints[m_nLastIndexPoint].y - m_dLowerLimit) * m_dVerticalFactor) ;

// add this line
m_dcPlot.MoveTo ((int)m_dPoints[m_nLastIndexPoint].x, (int)m_dPoints[m_nLastIndexPoint].y) ;
// End add
m_dcPlot.LineTo ((int)m_dPoints[m_nLastIndexPoint].x, (int)m_dPoints[m_nLastIndexPoint].y) ;
}

This may not be the correct method but I found it fixed my problem.

I also found that outside of the timer if I called AppendPoint() one after another I didn't get the correct display ( just the last points plotted) I just added OnPaint() to bottom of AppendPoint() amd that fixed that problem.

If these are not correct methods to fix my problems could you please help me out, I am attempting to learn this stuff faster than my little brain can handle.


Thanks and Regards

Darren


Questioncan u help me? Pin
pjp_eee19-Jan-04 0:01
susspjp_eee19-Jan-04 0:01 
AnswerRe: can u help me? Pin
Darren_vms12-Feb-04 2:35
Darren_vms12-Feb-04 2:35 
GeneralClistViewCtrl with different colors for rows for wince Pin
Bilal Ahmad30-Nov-03 21:09
Bilal Ahmad30-Nov-03 21:09 
QuestionIs it working at all? Pin
11-Feb-02 1:17
suss11-Feb-02 1:17 
AnswerRe: Is it working at all? Pin
Stober17-Sep-03 4:46
Stober17-Sep-03 4:46 
GeneralGraph Control Pin
13-Jan-02 15:20
suss13-Jan-02 15:20 
GeneralRe: Graph Control Pin
garkhov_major11-Mar-05 4:30
garkhov_major11-Mar-05 4:30 
GeneralNot run Pin
19-Dec-01 23:01
suss19-Dec-01 23:01 
QuestionHow about no MFC example Pin
Paul Gibson19-Nov-01 12:36
Paul Gibson19-Nov-01 12:36 

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

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