I would like to draw a graph (on a PictureBox) using Graphics in VB.net
The input values are added over some time which need to be presented as graph.
But the problem I am facing is, I need to draw the entire graph from scratch every time a new point is defined. I know, this requires persisting the existing image. But that only allows redrawing the graphics, but not to make incremental changes (on the image) over time.

Recommended Answers

All 6 Replies

I'm not very sure if a PictureBox is best, depending perhaps a Panel control would do. I also think that the graph's background (axis, axis divisions, text and so on) may persist in a bitmap and employ a Graphics instance gr = Graphics.FromImage(bmp) to draw the rest.

Did you consider the chart control?

@ddanbe. No I did not try that. I am using graphic function drawcurve() and pass the array of points to this function.
I think that graphics functionality repaints the whole Picturebox (or any other container) right from scratch everytime it is called. As I get the inputs periodically, I am unable to incrementally show the advancement of the curve. I can do it when all points are obtained. Or I have to keep redrawing every thing when new data is to be added. If this functionality is there in chart control that would be great.
@xrj: Persisting graph on a control only helps when the control is obscured (say when the form is minimized and maximized again) but did not permit incremental increases to the curve.

Have a look at the DoubleBuffered property of the form if screen flicker is too much.
I know too little of the chart control, but googling "dymanic update in chart control in vb.net" should help. Success!

Suppose code Click Here was adopted for a window's panel control. Suppose again, in a given instant the panel has drawn points (x0,y0) (x1,y1)... (xi,yi) ...,(xn,yn) and then a new point, say (h,f(h)), must be drawn between point (xi,yi) and (x(i+1),y(i+1)) because xi<h<x(i+1). Redrawing problem is, now, to repaint rectangle((xi-1,ymax);(xi+1,ymin)), where ymax=max{yi-1,f(h),yi+1} ymin=min{yi-1,f(h),yi+1}. This, if points are joined by lines; if not, depending, more points should be considered, for ex. rectangle((xi-2,ymax);(xi+2,ymin) and ymax=max{yi-2,yi-1,f(h),yi+1,y+2} ymin=min{yi-2,yi-1,f(h),yi+1,y+2} in case of a cuadratic interpolation.

sorry for the index mistakes, let me retry: ...then a new point, say (h,f(h)), must be drawn between point (xi,yi) and (x(i+1),y(i+1)) because xi<h<x(i+1). Redrawing problem is, now, to repaint rectangle((xi,ymax);(xi+1,ymin)), where ymax=max{yi,f(h),yi+1} ymin=min{yi,f(h),yi+1}. This, if points are joined by lines; if not, depending, more points should be considered, for ex. rectangle((xi-1,ymax);(xi+2,ymin) and ymax=max{yi-1,yi,f(h),yi+1,yi+2} ymin=min{yi-1,yi,f(h),yi+1,y+2} in case of a cuadratic interpolation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.