Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

JvCoach23

VB.Net newbie

MS Sql Vet

Posted

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

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

Posted

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:

Posted
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.

JvCoach23

VB.Net newbie

MS Sql Vet

Posted
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

JvCoach23

VB.Net newbie

MS Sql Vet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...