Solved

Draw Oscilloscope line chart on a Windows Form

Posted on 2004-03-30
6
2,212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 10

Expert Comment

by:eternal_21
ID: 10721952
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
ID: 10723603
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
ID: 10724176
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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 1

Author Comment

by:stone123
ID: 10724264
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
ID: 10725370
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
ID: 10730235
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

615 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