I had this need to show some statistics through a graph in real-time, in a demo application which I wrote. The screenshot should illustrate clearly the idea behind this graph component. It will be useful for programmers who would like to track data in real-time, such as in data acquisition and analysis. I did not have time to develop something really elaborate, like different graph types, presentation options, and filters, but it should be very easy to add-on these functionalities from the code.
Using the code
Some of the features of this graph component are:
- A user-defined cache (list) for storing the graph data
- When data "overflows" the cache, the graph automatically discards the oldest data to create space for the latest data
- Moving average is calculated on-the-fly
It is very easy to include this code into any OpenGL-based application. The programmer only needs to make sure he/she has the rendering context.
void init ( GLvoid )
glClearColor(0.0f, 0.0f, 0.0f, 0.f);
myGraph = OGLGraph::Instance();
myGraph->setup( 500 , 100 ,
10 , 10 ,
2 , 2 ,
1 , 200 );
void display ( void )
float time = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
value = 5*sin( 5*time ) + 10.f;
myGraph->update( value );
Source code builds nicely in MS VS.NET 2003.
Points of Interest
You can include any filters like noise reduction, low-pass, or high-pass in the
update() code, or even pass post-processed data into this function if you can do that with an external software (e.g., using Matlab).