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 Kb
Download source - 18 Kb


Comments

  • Bug

    Posted by Enzo69 on 12/14/2008 08:24am

    In 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 ...

    Reply
  • Another open-source real-time plotter can be found at http://www.live-graph.org

    Posted by gragus on 05/24/2007 06:11am

    Another 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.

    Reply
  • Please help me~

    Posted by drumist on 03/26/2007 06:30am

    Hi~ 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

    Reply
  • ActiveX Control

    Posted by Legacy on 08/14/2003 12:00am

    Originally 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!!!

    Reply
  • Good code... minor bug

    Posted by Legacy on 02/24/2003 12:00am

    Originally 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!

    Reply
  • Bug report

    Posted by Legacy on 01/28/2003 12:00am

    Originally 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)
    m_pValues[0].YValue = value;

    Reply
  • Plotting Missed points

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

    Originally 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

    Reply
  • visual worker

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

    Originally posted by: xfxty

    I had downloaded your source code ,very good,Thanks.

    Reply
  • RT.shtml

    Posted by Legacy on 05/29/2002 12:00am

    Originally posted by: Konstantin

    Thanks! Very useful thing!

    Reply
  • some help

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

    Originally posted by: Peter

    Hello,
    
    I download your application,it is really good,bud the source is too difficult for me.Could you send me some help files or something like that,please.
    Peter

    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: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • 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 …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds