Want to draw continuous line based on a function
-
Hello, Let's say I have a function, exp^x for example. I would like to draw a graph of this function in the client area of my form. The only way I can think of doing this is to write a conditional loop that will iterate through values of x within some interval and then draw the value onto the screen scaled in some way to the clientRect.Height and clientRect.Width. Question: What do I have to do to get the 'graph' to appear as one continuous smooth plot? thanks
-
Hello, Let's say I have a function, exp^x for example. I would like to draw a graph of this function in the client area of my form. The only way I can think of doing this is to write a conditional loop that will iterate through values of x within some interval and then draw the value onto the screen scaled in some way to the clientRect.Height and clientRect.Width. Question: What do I have to do to get the 'graph' to appear as one continuous smooth plot? thanks
Create a Point for every x/y coordinate you have, put them all into an array and then call:
Graphics g = e.Graphics; //assuming you are in OnPaint
Point[] points = CalculatePoints();
g.DrawLines(Pens.Black, points);You can also play around with the SmoothingMode property of the Graphics class. This will probably help you to make it look 'nicer'.