15,942,756 members
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

## Solution 1

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?

## Solution 2

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.

:)

v2

## Solution 3

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

v2

## Solution 4

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.

v2