Solved

Draw Oscilloscope line chart on a Windows Form

Posted on 2004-03-30
6
2,135 Views
Last Modified: 2012-05-05
Experts,

I am trying to draw oscilloscope-like line chart on a Windows Form in C#. The data contains thousands of sample points along certain time period. so the line easily gets to exceed the border of the form.
I wonder if there is any way I can add a scroll bar so that  the points with X-coordinates beyond the limit of the form can be seen, instead of being clipped out.

Thanks a lot
stone
0
Comment
Question by:stone123
6 Comments
 
LVL 10

Expert Comment

by:eternal_21
Comment Utility
No there is not, unfortunately.  Why don't you create an image in memory, and draw on that?  Then you have a PictureBox object on your form that you can set to display your image every time you add a point.  The PictureBox would then have scroll bars.  Or create a custom control that you will draw to instead.

But what I am really wondering is why you don't just size your output to the form's current size?
0
 
LVL 9

Expert Comment

by:msdixon
Comment Utility
it can be done. i did the exact same thing. i didn't want to resize or distort the graph.

i used a panel within a panel, and drew on the child panel. if the x coordinate was greater than the width, i increased the child panel's width to the x value. and i set the parent panel's autoscroll property to true.
0
 
LVL 1

Author Comment

by:stone123
Comment Utility
It sounds like a good idea, msdixon. However, when I move the scroll bar, the line changes its length. it becomes shorter than the original one.

you will see the same effect if you try the following code.
      
Graphics g = panel1.CreateGraphics();
Pen myPen = new Pen(Color.Blue);
myPen.Width = 2;
panel1.Width = 2000;
pnlCanvas.Refresh();
g.DrawLine(myPen, 0, 50, 2000, 50);

Thanks a lot

stone
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:stone123
Comment Utility
This is to eternal_21,

How do you draw a line on a System.Drawing.Image object? Can you provide more detail?

Thanks.
0
 
LVL 9

Assisted Solution

by:msdixon
msdixon earned 100 total points
Comment Utility
if i remember right, i had to override the paint event, and redraw the graph every time. it also had some flicker, but that's another issue.
0
 
LVL 11

Accepted Solution

by:
Agarici earned 150 total points
Comment Utility
if you want to draw on an Image object you can do something like:

Graphics g = Graphics.FromImage( <your image> )
g.drawline(...)

but:
if you really have a large number of  points you coudl draw only a range of point that fit the width of the display area and use a scrollbar control to change only the position where the range of points 'to be drawn' starts (and ends).

this way you won't have to use an extra picturebox nor draw in a image
and i think it will be faster


hth.

A.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now