Click here to Skip to main content
15,942,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,
I want to draw a path by c++, Window Form
the path is based on two variables, x and y
and both variables change w.r.t time
Therefore, I want the program to plot x and y on the graph every 0.5s

Here is my code
Color Black=Color::FromArgb(250, Color::Black);
   SolidBrush^ myBrush = gcnew SolidBrush( Black );
   if (x!=0 $$ y!=0)
   {
       CallerGDI-> FillRectangle(myBrush,x,y,1,1); //draw point

   };

But my program can only plot the first point, am I missing something

p.s Actually x and y are signals come from a serial port
Posted
Updated 7-Feb-10 3:52am
v6

Your posted code is painting one pixel. That is the working part of your project.

And where ist the timer function or the loop computing new values for x and y?
 
Share this answer
 
Your plotting function should draw the entire graph (i.e. a set of points -or lines-) each time is called. Hence you have to store the read points, scale properly and then plot all of them (or, at least, a fixed number of most recent ones).

And yes, you may use an array to store read values.

Please modify your original post, insted of adding fake answers.
:)
 
Share this answer
 
v2
re stebich :

x and y are some signals come from a serial port
so it is changing when the program is listening the serial port
Thanks

re CPallini:
How can I store those changing variables?
By using List structure? or array?
Thanks
 
Share this answer
 
v2
You can store all the x and y pairs as a vector of POINT structures.
std::vector<POINT> ptGraph;

You can then use the GDI Polyline[^] to draw the entire graph in one shot.
If you have multiple lines to be drawn, you can use the PolyPolyline[^] function.

If you can use GDI+, you the Graphics::DrawPolygon[^] function.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900