Question

I am using a ZedGraphControl in a WindowsForms project in C#. The ZedGraphControl is V5.1.5.

The data in the control is static and I add it all before the form is shown. The X axis of the data consists of numbers indicating seconds offset from the beginning. in other words from 0 to some number of seconds.

I want to initially show the last 5 seconds, but provide a horizontal scrollbar so the user can scroll back and forth. I set the "graphPane.XAxis.Scale.Max = maxX;" where maxX is the largest X value in my data. I set the "graphPane.XAxis.Scale.Min = maxX - 5;".

The data starts off displaying the way I want it, but when the user scrolls the horizontal bar, bizzar behavior occurs.

As you drag the thumb of the scrollbar to the left, the beginning of the data shown in the grid moves to the lower values as expected, and the thumb of the scrollbar moves to the left, but the right edge of the thumb stays at the right of the scrollbar and you cannot move back to the right. It is as if the data to the right of the viewing range gets truncated as you scroll left.

I cannot find any reason for this nor any way to control it. Does anyone have any ideas about this behavior?

Was it helpful?

Solution

Ok, found it myself.

I found a fine article that describes scrolling:

Add a ScrollBar

In it the author specifically says "the scrolling will be wacky because the scrollable range has not been set".

I used the sample "Manually Setting the Scroll Range" and the part that I was missing is setting the zedGraphControl1.ScrollMinX and zedGraphControl1.ScrollMaxX properties. Once I defined these values everything started working as expected. I also found that in my case, the value of zedGraphControl1.IsAutoScrollRange had no effect, but I left it set to false to be consistent with the example. This would probably have an effect if the dataset is dynamic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top