问题
I have made a chart which dynamically draw a spike when data received. In this chart I have made a scrollbar, so only 20 datapoints get shown at on time.
public void Chart()
{
ChartArea mov = SleepMovChar.ChartAreas["Movement"];
mov.AxisX.ScrollBar.Size = 12;
mov.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
mov.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.All ^ ScrollBarButtonStyles.ResetZoom;
mov.AxisX.ScrollBar.IsPositionedInside = true;
mov.AxisX.ScrollBar.Enabled = true;
mov.AxisX.ScaleView.Size = 20;
}
My problem is, that I want that scrollbar to move to right when data received. At the time now, it moves to left, so the first data is shown. I just want that the latest data is shown instead, so that the scrollbar follows the data receive.
回答1:
If you want the visible area to follow the new data like in an oscilloscope, you can set the scroll position :
Series S1 = SleepMovChar.Series["yourSeriesByNameOrNumber"];
mov.AxisX.ScaleView.Position = S1.Points.Count - mov.AxisX.ScaleView.Size;
You will need to repeat this whenever you have added data points..
来源:https://stackoverflow.com/questions/27250118/scrollbar-moving-to-right-instead-of-left