Link to home
Start Free TrialLog in
Avatar of jfburke1
jfburke1

asked on

Real-time C# plotting

I used onPaint in a C# Windows application (a windows FORM) to draw a 2-D line plot.  Now I would like to refresh that plot periodically with new data.  How could I do that?  Any help would be great.
Avatar of jfburke1
jfburke1

ASKER

Sorry about the MFC zone reference.  As the question indicates, I am a beginner...
Avatar of Bob Learned
If you are using the Paint event to draw, then you can use the Invalidate method to force a paint to redraw.

Bob


I actually went a new route with the C# code...I now am creating an event and then maually calling that event every 50 ms in order to plot the data that I am acquiring through an optical data acquisition card.  

The goal is to plot the data in real-time by updating a plot every 50 ms.  I know this is possible because I have interfaced with the card in Matlab and have made such a plot.  But now, I want lower level control of the card - thus the C# code.  

The problem is that the plotting is taking forever in C# (much slower than Matlab) using my event triggered straegy - the program is currently non-functional.  Does anyone know why the plotting takes so long in C#? Or, what would be the most efficient manner of sequential "real-time" plotting in C#?

jfburke1
How intensive is the plotting algorithm?

Bob
I am not quite sure what you mena by intensive...but we are reading in data sampled at 32000 Hz and want to plot ~6 sec of data on the screen.  That would translate  to about 192,000 samples that have to be plotted every 50 ms.  Realistically, we plot the downsampled data (dowsampled to ~100 HZ) so actually we would only be plotting about 6000 samples each 50 ms iteration, but we would not like to limit our downsampling rate (which affects our processing of the data) by the time it takes to display the data: therefore, we would like to be able plot all 192,000 samples.
If you are not quite sure what intensive means, then let me say that what you described is intensive.  What are you using to plot these samples?  Are you using a GraphicsPath, DirectX, OpenGL, ...?

Bob
Bob,

I really appreciate your help (I saw your EE ranking!).  I am an electrical engineer and have difficulty with designing software so thanks for your patience.  Currently, I am drawing the graph by creating a Graphics object in the Form1 class using CreateGraphics();.  Then I pass this object (I call it g) to my plotting class where I execute the following code:

Pen aPen = new Pen(LineStyle.LineColor, LineStyle.Thickness);
aPen.DashStyle = LineStyle.Pattern;

foreach(ArrayList aL in dc.DataSeriesList)
{
    for(int i = 1; i <  aL.Count ; i++)
        {
              g.DrawLine(aPen, [normalized X-Y Data for new Point[1]],  [normalized X-Y Data for new Point[0]])
        }
 }

 aPenn.Dispose()


Notes:  (1) I have defined a class linestyle to hold the information aboiut the line
             (2) The dc object holds an arraylist of arraylists that each point to a vector of short data types
                   representing the data grabbbed every 50 ms.
             (3) I believe the rendering used for this graphics scheme is GDI+.

Thanks again for your help,

John
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Bob for the solution!