在ResetAutoValues上缩放图表
本文关键字:缩放 ResetAutoValues | 更新日期: 2023-09-27 17:51:11
我正在使用图表来绘制来自传感器的一些信息。一切都很顺利,直到我到达3660点的区间。所以,我想做的是当我的点达到这个值时,我的图表将删除第一个点并添加新的点,看一下代码:
if (graficoKVm.Series[0].Points.Count > 3660)
{
graficoKVm.Series[0].Points.RemoveAt(0);
graficoKVm.Series[0].Points.AddXY(DateTime.Now.ToOADate(), _sensorCampoEletroMagnetico.kVm);
graficoKVm.ResetAutoValues();
}
问题是,如果图表缩放,当它执行graficoKVm.ResetAutoValues();
时,我的缩放变得混乱。到目前为止,我已经尝试存储缩放值,然后在重置后应用缩放,但我没有实现它。下面是图表声明:
this.graficoKVm.BackColor = System.Drawing.Color.Black;
this.graficoKVm.BorderSkin.BorderColor = System.Drawing.Color.White;
chartArea1.AxisX.Interval = 5D;
chartArea1.AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Minutes;
chartArea1.AxisX.LabelStyle.Angle = 45;
chartArea1.AxisX.LabelStyle.ForeColor = System.Drawing.Color.White;
chartArea1.AxisX.LabelStyle.Format = "HH:mm";
chartArea1.AxisX.LineColor = System.Drawing.Color.White;
chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.White;
chartArea1.AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
chartArea1.AxisX.MajorTickMark.LineColor = System.Drawing.Color.White;
chartArea1.AxisX.MinorGrid.LineColor = System.Drawing.Color.White;
chartArea1.AxisX.MinorTickMark.LineColor = System.Drawing.Color.White;
chartArea1.AxisX.ScaleBreakStyle.LineColor = System.Drawing.Color.White;
chartArea1.AxisX.ScaleView.SizeType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Minutes;
chartArea1.AxisX.ScaleView.SmallScrollMinSize = 5D;
chartArea1.AxisX.ScaleView.SmallScrollMinSizeType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Minutes;
chartArea1.AxisX.ScaleView.SmallScrollSizeType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Minutes;
chartArea1.AxisX.ScrollBar.BackColor = System.Drawing.Color.LightGray;
chartArea1.AxisX.ScrollBar.ButtonColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
chartArea1.AxisX.ScrollBar.LineColor = System.Drawing.Color.Black;
chartArea1.AxisX2.LineColor = System.Drawing.Color.White;
chartArea1.AxisX2.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
chartArea1.AxisX2.ScrollBar.BackColor = System.Drawing.Color.LightGray;
chartArea1.AxisX2.ScrollBar.ButtonColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
chartArea1.AxisX2.ScrollBar.LineColor = System.Drawing.Color.Black;
chartArea1.AxisY.Interval = 2D;
chartArea1.AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
chartArea1.AxisY.LabelStyle.ForeColor = System.Drawing.Color.White;
chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.White;
chartArea1.AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
chartArea1.AxisY.MajorTickMark.LineColor = System.Drawing.Color.White;
chartArea1.AxisY.Maximum = 18D;
chartArea1.AxisY.Minimum = -18D;
chartArea1.AxisY.MinorGrid.LineColor = System.Drawing.Color.White;
chartArea1.AxisY.MinorTickMark.LineColor = System.Drawing.Color.White;
chartArea1.AxisY.ScaleBreakStyle.LineColor = System.Drawing.Color.White;
chartArea1.AxisY.ScaleView.SmallScrollMinSize = 0.5D;
chartArea1.AxisY.ScaleView.SmallScrollSize = 0.5D;
chartArea1.AxisY.ScrollBar.BackColor = System.Drawing.Color.LightGray;
chartArea1.AxisY.ScrollBar.ButtonColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
chartArea1.AxisY.ScrollBar.LineColor = System.Drawing.Color.Black;
chartArea1.AxisY2.LineColor = System.Drawing.Color.White;
chartArea1.AxisY2.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
chartArea1.AxisY2.ScrollBar.BackColor = System.Drawing.Color.LightGray;
chartArea1.AxisY2.ScrollBar.ButtonColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
chartArea1.AxisY2.ScrollBar.LineColor = System.Drawing.Color.Black;
chartArea1.BackColor = System.Drawing.Color.Black;
chartArea1.BorderColor = System.Drawing.Color.White;
chartArea1.CursorX.Interval = 0.01D;
chartArea1.CursorX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Minutes;
chartArea1.CursorX.IsUserEnabled = true;
chartArea1.CursorX.IsUserSelectionEnabled = true;
chartArea1.CursorX.SelectionColor = System.Drawing.Color.White;
chartArea1.CursorY.IsUserEnabled = true;
chartArea1.CursorY.IsUserSelectionEnabled = true;
chartArea1.CursorY.SelectionColor = System.Drawing.Color.White;
chartArea1.InnerPlotPosition.Auto = false;
chartArea1.InnerPlotPosition.Height = 91.06797F;
chartArea1.InnerPlotPosition.Width = 95F;
chartArea1.InnerPlotPosition.X = 5F;
chartArea1.InnerPlotPosition.Y = 2.16495F;
chartArea1.Name = "ChartArea1";
chartArea1.Position.Auto = false;
chartArea1.Position.Height = 97F;
chartArea1.Position.Width = 97F;
this.graficoKVm.ChartAreas.Add(chartArea1);
this.graficoKVm.Location = new System.Drawing.Point(3, 270);
this.graficoKVm.Margin = new System.Windows.Forms.Padding(0);
this.graficoKVm.Name = "graficoKVm";
series1.BorderWidth = 2;
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
series1.IsVisibleInLegend = false;
series1.Name = "Valor";
series1.ShadowColor = System.Drawing.Color.Black;
series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
this.graficoKVm.Series.Add(series1);
this.graficoKVm.Size = new System.Drawing.Size(1201, 295);
this.graficoKVm.TabIndex = 27;
this.graficoKVm.Text = "chart1";
您是否尝试在您的代码中使用Refresh
或Update
?当指数达到3660时,图表将使用保存在您的系列中的Point
重新绘制,无论您应用了多大的缩放。
为了使它以正确的方式工作,我做了这样的实现:
if (graficoKVm.Series[0].Points.Count > 3659)
{
graficoKVm.Series[0].Points.AddXY(DateTime.Now.ToOADate(), _sensorCampoEletroMagnetico.kVm);
if (!graficoKVm.ChartAreas[0].AxisX.ScaleView.IsZoomed &&
!graficoKVm.ChartAreas[0].AxisY.ScaleView.IsZoomed &&
!graficoKVm.ChartAreas[0].AxisY2.ScaleView.IsZoomed &&
!graficoKVm.ChartAreas[0].AxisX2.ScaleView.IsZoomed)
{
while (graficoKVm.Series[0].Points.Count > 3660)
{
graficoKVm.Series[0].Points.RemoveAt(0);
}
graficoKVm.ResetAutoValues();
}
}
因此,如果图表在任何轴上缩放,则不会重置每个轴的最小值和最大值。消除缩放问题