jvcoach23 Posted November 15, 2004 Posted November 15, 2004 I'd like to do a little charting, something real simple. I don't want to use Dundas or have to pay for any charting components.. I'm really just wanting to learn. I've 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. I'll only have one set of data for right now.. just need somone to help me out. thanks Shannon Quote JvCoach23 VB.Net newbie MS Sql Vet
ThePentiumGuy Posted November 15, 2004 Posted November 15, 2004 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 Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Ming_Lei Posted November 15, 2004 Posted November 15, 2004 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 else's 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: Quote
jvcoach23 Posted November 16, 2004 Author Posted November 16, 2004 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.. i've 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.. won't this draw when the form loads.. I can't 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. I'd 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. Quote JvCoach23 VB.Net newbie MS Sql Vet
Ming_Lei Posted November 17, 2004 Posted November 17, 2004 If it is not painting after change of data, call Refresh(). Quote
jvcoach23 Posted November 17, 2004 Author Posted November 17, 2004 If it is not painting after change of data' date=' call Refresh().[/quote'] thanks it's painting... but what I'm not figuring out is this. for me to get it to paint at all I have to use the Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs) but on this form I'm 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 Quote JvCoach23 VB.Net newbie MS Sql Vet
ThePentiumGuy Posted November 17, 2004 Posted November 17, 2004 If it is not painting after change of data' date=' call Refresh().[/quote'] It's Me.Invalidate() ;). THat'll call OnPaint when u want Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.