Append to canvas

How do I keep drawn objects on canvas?

I’m taking serial data and plotting on a canvas. However the old g.FillOval disappears. What am I missing?

[code]Dim i as Integer
dim yValue as Integer
dim readValue as string

yValue = 50

//Back Ground
g.ForeColor=RGB(255,255,255)
g.FillRect(0,0,me.width,me.Height)

// Grid
g.ForeColor=RGB(127,127,127)

For i = 0 to me.width Step 20
//g.DrawLine(x1,y1,x2,y2)

//vertical
g.DrawLine(i,0,i, me.Height)

//horizontal
g.DrawLine(me.width,me.height-i,0,me.height-i)

next

// Draw data point
g.ForeColor= rgb(255,0,0)
g.FillOval(xPos, yValue,5,5) //timer property[/code]

If you’re doing this inside a Paint event then you will be clearing the “old” data points with your fillrect every paint.

Try moving the drawing outside the paint, draw on a picture instead then use DrawPicture inside the paint to actually put the image on the canvas.

You then have the ability to add points to the picture when you want (as you get data on from serial port) and just call invalidate, refresh or refrectrect (on the portion of the image you want to update) to show the change.

Here’s a really simple example I wrote for someone a while back

https://www.dropbox.com/s/rduxbjwkgp3yzzn/PaintBuffer.xojo_binary_project?dl=1

you can strip out the image resizing code if you dont need it.