Depending on what you want there are several choices. My guess is that you want to keep all data points and simply want to add a scrollbar. To do you can write:
ChartArea A1 = chart1.ChartAreas["yourChartAreaByNameOrNumber"];
A1.AxisX.ScrollBar.Size = 12;
// show either just the center scroll button..
A2.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
// .. or include the left and right buttons:
A1.AxisX.ScrollBar.ButtonStyle =
ScrollBarButtonStyles.All ^ ScrollBarButtonStyles.ResetZoom;
// looks better inside, but ymmv
A1.AxisX.ScrollBar.IsPositionedInside = true;
A1.AxisX.ScrollBar.Enabled = true;
A1.AxisX.ScaleView.Size = 100; // number (!) of data points visible
You may want to play with the size and placement. Please pick the number of data points you want to have visible at any time..
If you want the visible area to follow the new data like in an oscilloscope, you can set the scroll position :
Series S1 = chart1.Series["yourSeriesByNameOrNumber"];
A1.AxisX.ScaleView.Position = S1.Points.Count - A1.AxisX.ScaleView.Size;
Note that you need to set it again after adding any data!
If you also want to let the users adapt the zoom range set
A1.AxisX.CursorX.IsUserSelectionEnabled = true;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…