Drawing our Own Charts on Forms with out using the MSChart Control
-
Hi Every one i am making a project, in which i need to draw the charts by means of simple drawing methods as used in VB.Net. So that i can make any type of chart i want to draw. I want to draw the charts like in MS Acess. Thanks Eman Ali.
Great! And your question is? RageInTheMachine9532
-
Great! And your question is? RageInTheMachine9532
-
First, I have to question why you would want to do this? There are many controls already out there that handle chart drawing of any imaginable type. I just don't see the point in reinventing the wheel...? But if you must, you could use a PicBox or draw directly on the Form itself. I would suggest writing this as a control using a PicBox so it can be reused in other projects. First, you have to work out a method of keeping track of data. This is going to depend on the type of data your working with. Then, you calculate the scaling for your data, then calculate the size of your chart and its scaling in the PicBox. Your also going to have to calculate positions for labels and font scaling. When you have all that, you have to write your code to paint the chart in the Paint event of your control. Get a Graphics object for the PicBox by using the CreateGraphics method of the PicBox. Then you can use the Graphics objects methods to draw what your chart is going to look like. Just as an example of drawing using the Graphics object, this is a little snippet of code from a goofy little control project I worked on a while back:
Private Sub threadDrawingLines() Dim x As Integer Dim objPen As New Pen(Color.Blue) Dim grPicBox As Graphics = PictureBox1.CreateGraphics Try While (pNumberOfLines > 0) For x = 1 To pNumberOfLines grPicBox.DrawLine(objPen, Lines(x, 1), Lines(x, 2)) Next UpdatePositions() Thread.Sleep(pSleepTime) End While Catch ex As ThreadAbortException grPicBox = Nothing objPen = Nothing End Try End Sub
RageInTheMachine9532
-
First, I have to question why you would want to do this? There are many controls already out there that handle chart drawing of any imaginable type. I just don't see the point in reinventing the wheel...? But if you must, you could use a PicBox or draw directly on the Form itself. I would suggest writing this as a control using a PicBox so it can be reused in other projects. First, you have to work out a method of keeping track of data. This is going to depend on the type of data your working with. Then, you calculate the scaling for your data, then calculate the size of your chart and its scaling in the PicBox. Your also going to have to calculate positions for labels and font scaling. When you have all that, you have to write your code to paint the chart in the Paint event of your control. Get a Graphics object for the PicBox by using the CreateGraphics method of the PicBox. Then you can use the Graphics objects methods to draw what your chart is going to look like. Just as an example of drawing using the Graphics object, this is a little snippet of code from a goofy little control project I worked on a while back:
Private Sub threadDrawingLines() Dim x As Integer Dim objPen As New Pen(Color.Blue) Dim grPicBox As Graphics = PictureBox1.CreateGraphics Try While (pNumberOfLines > 0) For x = 1 To pNumberOfLines grPicBox.DrawLine(objPen, Lines(x, 1), Lines(x, 2)) Next UpdatePositions() Thread.Sleep(pSleepTime) End While Catch ex As ThreadAbortException grPicBox = Nothing objPen = Nothing End Try End Sub
RageInTheMachine9532
tahkns for the help. Its mean that what i was doing is write i am making my own charts . The reason why , which you have asked , The answer is that i have devoloped the clases for printing so what ever i draw on the panel will go as an output to the printer. And the project on which i am working is a document formatter which is connected to some data sourse and the charting facility like Acces is a main module for the project. so Thats why i am doing all my own.