سؤال

I´m using a chart to plot some infos from a Sensor. Everything is going right, until I reach the interval of 3660 points. So, what I want to do is when my points reach that value, my chart will remove the first point and add the new one, take a look at the code:

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();
}

The problem is that, if the chart is zoomed, when it execute the graficoKVm.ResetAutoValues(); my zoom got messed up. So far I´ve tried to store the zoom values and then apply the zoom after the reset, but I´ve failed implementing it. Here is the chart declaration:

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";
هل كانت مفيدة؟

المحلول 2

To make it work in the right way, I've done this implementation:

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();
    }
}

So, if the chart is zoomed on any Axis, it will not reset the min and max value from each Axis. Eliminating the zoom problem.

نصائح أخرى

Have you tried in your code to use Refresh or Update? When the index reaches 3660, the chart will be replotted with the Point saved in your series, no matter how much zoom you applied.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top