tags:

views:

508

answers:

2

How to draw square wave using ZedGraph?

I'm thinking about something like this:

alt text

My formula is:

y =  amplitude, if sin(x) >=0

y = -amplitude, if sin(x) < 0

In theory it should give a square wave, but gives me:

alt text

+2  A: 

It looks like it's stepping at discrete values along the X axis (which is really almost unavoidable), and drawing a steep (but still visibly non-vertical) line from the last point at which it sampled a positive sin(x), through sin(x)=0 to the next point at which it sample a negative sin(x).

The obvious cure is to tell it to sample the function at smaller intervals -- specifically, small enough so the transition from +1 to -1 (or vice versa) happens in less than the width of a pixel as you'll end up displaying it.

Jerry Coffin
it works - thanks.
oO
But it's not the solution, it is only fake, cheating our eye's perception. After zooming in, it will be still visible. You should change the step type for your curve (LineItem):line.Line.StepType = StepType.ForwardStep;
Gacek
+2  A: 

You should change the step type of your curve. Use:

line.Line.StepType = StepType.ForwardStep;

of course line is your LineItem object

Gacek
For reference: the other step type is `StepType.RearwardStep`. A demo can be found at: http://zedgraph.org/wiki/index.php?title=Smooth_Chart_Demo
Peter Mortensen