Hi @YUI-012 , Welcome to Microsoft Q&A,
To display scroll bars in a chart and implement smooth zooming and scrolling, you can control the size of the visible area by setting the ScaleView property of the AxisX. Specifically, when you have a large amount of data, you can limit the amount of X-axis data displayed and enable scroll bars to view all the data.
private void GraphRecord()
{
// Clear existing series
chart1.Series.Clear();
// Create two new series: Stage and Point-Stage
Series stageSeries = new Series("Stage");
Series pointStageSeries = new Series("Point-Stage");
// Set series type to Line
stageSeries.ChartType = SeriesChartType.Line;
pointStageSeries.ChartType = SeriesChartType.Line;
// Add series to chart
chart1.Series.Add(stageSeries);
chart1.Series.Add(pointStageSeries);
// Add test data
for (int i = 0; i < 20; i++)
{
// Use X axis for time/stage and Y axis for random values
chart1.Series["Stage"].Points.AddXY("Stage " + (i + 1), i * 2); // Assume Y value is i*2
chart1.Series["Point-Stage"].Points.AddXY("Stage " + (i + 1), i * 3); // Assume that the Y value is i*3
}
// Set the Y axis style
this.chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Gray;
this.chart1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Gray;
this.chart1.ChartAreas[0].AxisY.Maximum = 50; // Y axis maximum value, assumed to be 50
this.chart1.ChartAreas[0].AxisY.Interval = 5; // Y axis display interval
// Set the X axis style
this.chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Gray;
this.chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 30;
this.chart1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Gray;
this.chart1.ChartAreas[0].AxisX.Interval = 1;
// Enable scroll bar and zoom view
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = false; // Scroll bar outside
chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true; // Enable scroll bar
// Set the size of the default display area (for example, display 5 data points at a time)
int viewSize = 5;
if (chart1.Series["Stage"].Points.Count > viewSize)
{
chart1.ChartAreas[0].AxisX.ScaleView.Size = viewSize; chart1.ChartAreas[0].AxisX.ScaleView.Scroll(chart1.Series["Stage"].Points.Count - viewSize); } }
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.