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 ...
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..
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.
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 are never updated.
I solved the problem by adding this test to AddValue:
if (begin == m_nSize)
m_pValues.YValue = value;
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.