如何使用 c# 将图表的滚动条刻度视图位置设置为最近添加的值

本文关键字:位置 视图 设置 添加 最近 何使用 滚动条 | 更新日期: 2023-09-27 18:37:19

在我的应用程序中,我使用图表控件并每秒连续更新实时值。我为图表启用了滚动条,滚动条工作正常。但是我想始终将滚动条位置设置为最近添加的值(右侧)。请指导我,

 Chart chart = new Chart();
 Series series1 = new Series("testing");
 chart1.ChartAreas[0].CursorX.AutoScroll = true;
 chart1.ChartAreas[0].CursorY.AutoScroll = true;
 chart1.ChartAreas[0].AxisX.ScrollBar.Size = 15;
 chart1.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.All;
 chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = false;
 chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
 chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;                
 chart1.ChartAreas[0].AxisX.ScaleView.Zoom(2, 5);
 chart1.ChartAreas[0].RecalculateAxesScale();
  chart1.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Microsoft Sans Serif", 10, FontStyle.Bold);
  chart1.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Microsoft Sans Serif", 10, FontStyle.Bold);
  chart1.ChartAreas[0].AxisY2.TitleFont = new System.Drawing.Font("Microsoft Sans Serif", 10, FontStyle.Bold);

如何使用 c# 将图表的滚动条刻度视图位置设置为最近添加的值

最后,

我找到了将滚动条位置保持在最近添加的值的解决方案。

chart1.ChartAreas[0].AxisX.ScaleView.Position = chart1.ChartAreas[0].AxisX.Maximum;

AxisX.Maximum 是最近添加到图表的值。