Charting

jvcoach23

Well-known member
Joined
May 22, 2003
Messages
192
Location
Saybrook, IL
Id like to do a little charting, something real simple. I dont want to use Dundas or have to pay for any charting components.. Im really just wanting to learn. Ive been looking around the net.. and many have said you can use DGI+ to do some simple charting. I want to drive this chart with data from a database. Can someone help get me started. Ill only have one set of data for right now.. just need somone to help me out.

thanks
Shannon
 
Charts eh? Start out by using lines. Split your data into pairs... for example lets say this is your data:

(0,0), (1,1), (2,2), (3,3)

that would mean that there would be a line from 0,0 to 1,1.. 1,1 to 2,2... 2,2 to 2,3 so extract your data like so.

To graph:
in the Form1.Paint event use e.graphics.drawline and provide the x,y,x2,y2 arguments like so (x2 and y2 are the x and y coordinates of the 2nd point... it just draws a line through those 2 sets of point).

hope this helps,
-The Pentium Guy
 
About double buffering.

When drawing your chart, for example as real-time updating, I have found it is better to do double buffering. I am not sure if it is suitable for beginner, but if you want, here is a code I have modified from someone elses I found over the web:

Override the OnPaint handler as:
======================================
protected override void OnPaint(PaintEventArgs e)
{
if(_backBuffer==null)
{
_backBuffer=new Bitmap(this.ClientSize.Width,this.Client.Height);

}
Graphics g=Graphics.FromImage(_backBuffer);

//Paint your graphics on g here
g.FillRectangle(Brushes.White, 0, 0, _backBuffer.Width, _backBuffer.Height); // I use this to paint background with white.
//Continue to paint your stuff....


g.Dispose();
//Copy the back buffer to the screen
e.Graphics.DrawImageUnscaled(_backBuffer,-0,0);
//base.OnPaint (e); //optional but not recommended
}
=================================


Declare:
Bitmap _backBuffer.
:rolleyes:
 
ThePentiumGuy said:
Charts eh? Start out by using lines. Split your data into pairs... for example lets say this is your data:

(0,0), (1,1), (2,2), (3,3)

that would mean that there would be a line from 0,0 to 1,1.. 1,1 to 2,2... 2,2 to 2,3 so extract your data like so.

To graph:
in the Form1.Paint event use e.graphics.drawline and provide the x,y,x2,y2 arguments like so (x2 and y2 are the x and y coordinates of the 2nd point... it just draws a line through those 2 sets of point).

hope this helps,
-The Pentium Guy
thanks for the help.. ive played around a bit.. see how I can change the x1,x2,y1,y2 cordinates to make my line. however, when I use the onpaint.. wont this draw when the form loads.. I cant call it when I want.. or tell it to clear out and start with a fresh set of points?? not sure how that works.. hope ou can help. Id like to be able to select my data that I want.. then make a call to have the line paint.. sorry.. talking to a young pup here.
 
Ming_Lei said:
If it is not painting after change of data, call Refresh().

thanks

its painting... but what Im not figuring out is this. for me to get it to paint at all I have to use the

Code:
Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)

but on this form Im going to want to have some drop downs taht help decide what data is to be displayed. so how do you call the OnPaint when you want it, and not when the form loads. The above runs as soon as the form loads.

thanks
Shannon
 
Back
Top