Simple Real-time Class for Advanced Charts and Plotting
Click here for larger image
Environment: VC6, NT4 SP5, Windows 95b/98
In real time applications it is necessary to have some graphics functions which can make plotting using dynamic engineering data. The CRealTime class provide such functions which have been implemented using SDK rather than MFC.
1. Features: (1). Use permanent circular buffers to stored data rather than resize data storage or memory copy (2). Scroll through time automatically (3). Multi-line display with most property features at different time levels (4). Multiple legends and data annotations (5). Scroll and zooming (6). Memory Device Context drawing (7). Printing
2. History
From Nov. 1999 to May 2000, I involved to write a multithread real-time simulation application using MFC on Windows NT. It communicates with several processes running on different machines through TCP/IP. One of its features is real-time plotting, logging, and periodic background printing with data received from other processes.
However, the provided class, which has been rewritten using Win32 API completely rather than MFC, only implements part of the original MFC CRealTime class. Due to time constraints, logging, periodic background printing, read and write locking, and multithread features have not been rewritten. Therefore, those features are not included in the above class.
You are free to use or modify this class and to use it in any of your applications. But I make no guarantees about this class suitability for use. If there is any problem with anything I wrote, I will certainly try to help solve it.
3. Source Code
(1). ClassArr.h: template based class to implement dynamic array. It is similar to CArray in MFC but independent on MFC.
(2). Graphics.h and Graphics.cpp: property definition and drawing framework description.
(3). Random.h and Random.cpp: a portable subtractive pseudorandom number generator, which is faster than rand() in C Run time. It generates and simulates new data coming in.
(4). RealTime.h and RealTime.cpp: CGraphics derived component and contains most of the real-time plot source.
(4). Str.h and Str.cpp: Simple string class.
4. Demo Project
The RTDemo, which is an MFC MDI application, demonstrates how to use CRealTime. It uses a splitter window, which includes two views (one for plot and the other for legends and data annotations). Please note that running RTDemo needs MSFlex grid 6.0 control, which comes with VC6.0.
From the Edit menu, you can test open Insert, Delete, and Modify a line at run time. The Property menu includes grid, boundary, title, memory drawing, and back color properties. Kill and restore timer can be found in the View menu. Right click in the top view, the Timer Speed menu will popup, and you can select one of 10 timer speed levels. Also you can drag a vertical line on the slider bar by clicking the left mouse button.
About the Author
I am a senior software engineer for TechComm Simulation Pty Ltd., Sydney, Australia, where I specialise in Client/Server and TCP/IP programming on Unix and Windows NT. My e-mail address is yuantuh@techsim.com.au.
Downloads
Download demo project - 63 KbDownload source - 18 Kb

Comments
Bug
Posted by Enzo69 on 12/14/2008 08:24amIn your demo, SetData comes before m_Graph.UpdateTimeRange and in the latter you handle the roll out of m_nBegin; so there is the danger that SetData use an index out of range. A possible solution is to move the check in AddYValue in the class CRealTime ...
ReplyAnother open-source real-time plotter can be found at http://www.live-graph.org
Posted by gragus on 05/24/2007 06:11amAnother tool for real-time plotting is LiveGraph. It comes with a well commented open source and a tutorial, so it is a good demo on how to code this sort of thing yourself. See http://www.live-graph.org.
ReplyPlease help me~
Posted by drumist on 03/26/2007 06:30amHi~ I downloaded your application and source code. It is exactly what i want. But this code is difficult to understand... Could you give some help? (some kind of manual or document) I'll wait for.. Thanks
ReplyActiveX Control
Posted by Legacy on 08/14/2003 12:00amOriginally posted by: Ken T
You've got a great program, but I was wondering whether it would be possible for you to make an activeX control out of it. I think that would be awesome!!!
ReplyGood code... minor bug
Posted by Legacy on 02/24/2003 12:00amOriginally posted by: Paul
I liked your code and after some digging around and some tweaks, I was able to understand it pretty well. I successfully converted it to Unicode for my application.
I did run across a minor glitch that was tough to get to the bottom of. In the CRealTime class definition, you dimensioned m_sTempStr to 32. If you set the CyclesPerSec to some number, say 2, the ShowTime() will run over this limit when cTime needs 2 digits to convey hours, minutes, and seconds. I dimensioned it to 64 for my purposes because I altered PrintTime to send a longer string and used %02d instead of %2d when printing hh:mm:ss.
Again, great code. Thanks for the help!
ReplyBug report
Posted by Legacy on 01/28/2003 12:00amOriginally posted by: Hans Olav Nybo
Hi
I think I have found a small bug in the code:
In CALine::AddValue:
New data values are added to the end of the data buffers until 'end == m_nSize'. Then 'begin' is used as index into the buffers. The first time the buffer is full, everything works fine. The second time, however, it goes wrong:
'end'and 'begin' are both updated in CRealTime::UpdateTimeRange:
When 'begin == m_nDataPerLine', 'begin' is set to zero, and m_pValueTime is updated like this: m_pValueTime[begin++]. Thus, begin is incremented to 1.
Because of that 'begin' = 1 the next time CALine::AddValue is called and m_pValues[0] are never updated.
I solved the problem by adding this test to AddValue:
if (begin == m_nSize)
Replym_pValues[0].YValue = value;
Plotting Missed points
Posted by Legacy on 01/15/2003 12:00amOriginally posted by: Kala Bazari
First let me say that this is a very well written application.
In my opinion, one thing that is missing is that this one does not plot X-Axis accurately. If you happen to get a point that is delayed by a fraction (say received at 1.1 seconds instead of 1 second), this graph still plots the point at 1 second. Similarly, if we miss a point and get the next point at 2 seconds, this graph will still plot the point at 1 second. Basically, it is still a one dimentional plot and not a true 2-D plot.
Thanks for great code
Kala
Replyvisual worker
Posted by Legacy on 12/04/2002 12:00amOriginally posted by: xfxty
I had downloaded your source code ,very good,Thanks.
ReplyRT.shtml
Posted by Legacy on 05/29/2002 12:00amOriginally posted by: Konstantin
Thanks! Very useful thing!
Replysome help
Posted by Legacy on 03/29/2002 12:00amOriginally posted by: Peter
ReplyLoading, Please Wait ...