MSChart水平滚动导致不需要的图表区域宽度变化

本文关键字:区域 变化 滚动 水平 不需要 MSChart | 更新日期: 2023-09-27 17:56:23

当我水平滚动缩放的mschart时,我看到一个丑陋的图表区域闪烁(右边框),这是由其宽度的不必要变化引起的(这是由于水平滚动期间图表的缩放比例可变)。有什么想法可以改善吗?

代码示例:

DateTime zeroTime = new DateTime(1, 1, 1, 0, 0, 0);
int k = 0;
chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
chart1.Dock = DockStyle.Fill;
chart1.BackColor = Color.Salmon;
this.chart1.ChartAreas["ChartArea1"].CursorX.IsUserEnabled = true;
this.chart1.ChartAreas["ChartArea1"].CursorY.IsUserEnabled = true;
this.chart1.ChartAreas["ChartArea1"].CursorX.IsUserSelectionEnabled = true;
this.chart1.ChartAreas["ChartArea1"].CursorY.IsUserSelectionEnabled = true;
this.chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Zoomable = true;
this.chart1.ChartAreas["ChartArea1"].AxisY.ScaleView.Zoomable = true;
this.chart1.ChartAreas["ChartArea1"].AxisX.ScrollBar.IsPositionedInside = true;
this.chart1.ChartAreas["ChartArea1"].AxisY.ScrollBar.IsPositionedInside = true;
this.chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.SmallScrollMinSizeType =DateTimeIntervalType.Seconds;
this.chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.SmallScrollSizeType = DateTimeIntervalType.Seconds;
chart1.ChartAreas["ChartArea1"].CursorY.Interval = 0.1;
chart1.ChartAreas["ChartArea1"].CursorX.Interval = 5.0;
chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "HH:mm:ss";
chart1.ChartAreas["ChartArea1"].CursorX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Seconds;
for (int i = 0; i < 600; i++) 
{if (i < 200 ){k=i/10;} else if(i<400){k=20;}else{k=(600-i)/10;}; chart1.Series[0].Points.AddXY(zeroTime.AddSeconds(i * 5), 0 - k);}

MSChart水平滚动导致不需要的图表区域宽度变化

图表的大小调整可能受图表区的InnerPlotPosition属性的影响。此处的默认值InnerPlotPosition.Auto设置为 true,这会导致宽度更改。

可以通过切换到手动模式来停止图表宽度更改:

this.chart1.ChartAreas["ChartArea1"].InnerPlotPosition.Auto = false;
// optional:
this.chart1.ChartAreas["ChartArea1"].InnerPlotPosition.X = 0; // all values are percentage
this.chart1.ChartAreas["ChartArea1"].InnerPlotPosition.Y = 0;
this.chart1.ChartAreas["ChartArea1"].InnerPlotPosition.Height = 100; 
this.chart1.ChartAreas["ChartArea1"].InnerPlotPosition.Width = 100;