繁体   English   中英

如何限制图表上的数据收集?

[英]How do I limit the data collection on a chart?

我有一个C#程序,它每秒从Arduino Mega中读取数据四次,并在两个图表中显示数据,每个图表都有两组数据。 运行几个小时后,数据开始滞后。 我可以看到程序的大小随时间增长。 我认为问题在于图表在每个图表上都显示了1分钟的快照,但是程序只是不断收集数据并造成内存泄漏问题。 有没有一种方法可以将数据收集限制为一两分钟并转储旧数据?

这是我编写的第一个C#程序,我是个老屁(62岁),患有CRS“无法记住Sh_t”。

任何帮助将不胜感激。

布赖恩

程序数据收集

// load the main form and sets up the charts
    private void TelemetryForm_Load(object sender, EventArgs e)
    {


        intensityChart.ChartAreas.Add("area");
        intensityChart.Legends.Add("INTENSITY");
        intensityChart.Legends.Add("I SENSE");
        intensityChart.Series.Add("INTENSITY");
        intensityChart.Series.Add("I SENSE");
        intensityChart.Legends["INTENSITY"].Position.Auto = false;
        intensityChart.Legends["INTENSITY"].Position.Height = 10;
        intensityChart.Legends["INTENSITY"].Position.Width = 50;
        intensityChart.Legends["INTENSITY"].Position.X = 20;
        intensityChart.Legends["INTENSITY"].Position.Y = 0;

        intensityChart.Legends["I SENSE"].Position.Auto = false;
        intensityChart.Legends["I SENSE"].Position.Height = 10;
        intensityChart.Legends["I SENSE"].Position.Width = 50;
        intensityChart.Legends["I SENSE"].Position.X = 20;
        intensityChart.Legends["I SENSE"].Position.Y = 0;

        toolCapChart.ChartAreas.Add("area2");

        toolCapChart.Series.Add("CAPACITOR VOLTAGE");
        toolCapChart.Series.Add("TOOL VOLTAGE");
        toolCapChart.Legends.Add("CAPACITOR VOLTAGE");
        toolCapChart.Legends.Add("TOOL VOLTAGE");
        toolCapChart.Legends["TOOL VOLTAGE"].Position.Auto = false;
        toolCapChart.Legends["TOOL VOLTAGE"].Position.Height = 10;
        toolCapChart.Legends["TOOL VOLTAGE"].Position.Width = 50;
        toolCapChart.Legends["TOOL VOLTAGE"].Position.X = 20;
        toolCapChart.Legends["TOOL VOLTAGE"].Position.Y = 0;
        toolCapChart.Legends["CAPACITOR VOLTAGE"].Position.Auto = false;
        toolCapChart.Legends["CAPACITOR VOLTAGE"].Position.Height = 10;
        toolCapChart.Legends["CAPACITOR VOLTAGE"].Position.Width = 50;
        toolCapChart.Legends["CAPACITOR VOLTAGE"].Position.X = 20;
        toolCapChart.Legends["CAPACITOR VOLTAGE"].Position.Y = 0;

        timer1.Enabled = true;
        timer1.Start();

    }

    // adds the data to the charts
    public void chartRead(Double timeofday)
    {

        Double x = timeofday;
        Double z = 1 * timeofday;
        Double y = 6 * timeofday;
        int charttime = 240;


        FontHeight = -1;


        intensityChart.ChartAreas["area"].Position.Auto = false;
        intensityChart.ChartAreas["area"].Position.Y = 8;
        intensityChart.Series["INTENSITY"].Points.AddXY(DateTime.Now.ToLongTimeString(), mic_out);
        intensityChart.Series["I SENSE"].Points.AddXY(DateTime.Now.ToLongTimeString(), i_sense);
        intensityChart.Series["INTENSITY"].LegendText = "INTENSITY";

        intensityChart.Series["I SENSE"].LegendText = "I SENSE";
        intensityChart.Series["INTENSITY"].Color = Color.Blue;
        intensityChart.Series["I SENSE"].Color = Color.Orange;
        intensityChart.Series["INTENSITY"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
        intensityChart.Series["I SENSE"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
        intensityChart.Series["I SENSE"].YAxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Secondary;
        intensityChart.ChartAreas["area"].AxisX.Minimum = intensityChart.ChartAreas["area"].AxisX.Maximum - charttime;
        intensityChart.ChartAreas["area"].AxisX.Interval =charttime/6;


        intensityChart.ChartAreas["area"].AxisY.Minimum = 0;
        intensityChart.ChartAreas["area"].AxisY.Maximum = 100;
        intensityChart.ChartAreas["area"].AxisY.Interval = 10;
        intensityChart.ChartAreas["area"].AxisY.MajorTickMark.Enabled = false;
        intensityChart.ChartAreas["area"].AxisY.MajorTickMark.Interval = 5;
        intensityChart.ChartAreas["area"].AxisY2.MajorTickMark.Enabled = false;
        intensityChart.ChartAreas["area"].AxisY2.MajorTickMark.Interval = 5;
        intensityChart.ChartAreas["area"].AxisX.MinorTickMark.Interval = 5;
        intensityChart.ChartAreas["area"].AxisX.MinorTickMark.Enabled = true;
        intensityChart.ChartAreas["area"].AxisY.MinorTickMark.Interval = 5;
        intensityChart.ChartAreas["area"].AxisY.MinorTickMark.Enabled = true;
        intensityChart.ChartAreas["area"].AxisY2.Minimum = 0;
        intensityChart.ChartAreas["area"].AxisY2.Maximum = isenseYscale;
        intensityChart.ChartAreas["area"].AxisY2.Interval = isenseYscale/10;
        intensityChart.ChartAreas["area"].AxisX2.MinorTickMark.Interval = 5;
        intensityChart.ChartAreas["area"].AxisX2.MinorTickMark.Enabled = true;
        intensityChart.ChartAreas["area"].AxisY2.MinorTickMark.Interval = 1;
        intensityChart.ChartAreas["area"].AxisY2.MinorTickMark.Enabled = true;
        intensityChart.ChartAreas["area"].AxisY.Title = "INTENSITY";
        intensityChart.ChartAreas["area"].AxisY2.Title = "I SENSE";


        toolCapChart.ChartAreas["area2"].Position.Auto = false;
        toolCapChart.ChartAreas["area2"].Position.Y = 8;
        toolCapChart.Series["TOOL VOLTAGE"].Color = Color.Red;
        toolCapChart.Series["CAPACITOR VOLTAGE"].Color = Color.Green;
        toolCapChart.Series["CAPACITOR VOLTAGE"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
        toolCapChart.Series["TOOL VOLTAGE"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
        toolCapChart.Series["TOOL VOLTAGE"].YAxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Secondary;
        toolCapChart.Series["TOOL VOLTAGE"].LegendText = "TOOL VOLTAGE";
        toolCapChart.Series["CAPACITOR VOLTAGE"].LegendText = "CAPACITOR VOLTAGE";
        toolCapChart.Series["CAPACITOR VOLTAGE"].Points.AddXY(DateTime.Now.ToLongTimeString(), hv_sense);
        toolCapChart.Series["TOOL VOLTAGE"].Points.AddXY(DateTime.Now.ToLongTimeString(), tool_vin);
        toolCapChart.ChartAreas["area2"].AxisX.Minimum = toolCapChart.ChartAreas["area2"].AxisX.Maximum - charttime;

        toolCapChart.ChartAreas["area2"].AxisY2.Minimum =  0;
        toolCapChart.ChartAreas["area2"].AxisY2.Maximum = toolVoltageChart;
        toolCapChart.ChartAreas["area2"].AxisY.Minimum = 0;
        toolCapChart.ChartAreas["area2"].AxisY.Maximum =hvSenseChartYScale;
        toolCapChart.ChartAreas["area2"].AxisY2.MinorTickMark.Interval = toolVoltageChart/25;
        toolCapChart.ChartAreas["area2"].AxisY2.MinorTickMark.Enabled = true;
        toolCapChart.ChartAreas["area2"].AxisY2.MajorTickMark.Interval = 100;
        toolCapChart.ChartAreas["area2"].AxisY2.MajorTickMark.Enabled = false;
        toolCapChart.ChartAreas["area2"].AxisX.Interval = charttime/6;
        toolCapChart.ChartAreas["area2"].AxisX.MinorTickMark.Interval = 5;
        toolCapChart.ChartAreas["area2"].AxisX.MinorTickMark.Enabled = true;
        toolCapChart.ChartAreas["area2"].AxisY.MinorTickMark.Interval = hvSenseChartYScale/25;
        toolCapChart.ChartAreas["area2"].AxisY.MinorTickMark.Enabled = true;
        toolCapChart.ChartAreas["area2"].AxisY.MajorTickMark.Interval = 1000;
        toolCapChart.ChartAreas["area2"].AxisY.MajorTickMark.Enabled = false;
        toolCapChart.ChartAreas["area2"].AxisY2.Title = "TOOL VOLTAGE";
        toolCapChart.ChartAreas["area2"].AxisY.Title = "CAPACITOR VOLTAGE";

        capVoltageAngularGauge.Value = hv_sense;
        pulseIntensityLinearGauge.Value = mic_ph_out;
        pulseIntensityLinearGauge.Max = mic_ph_scaling;

调用series.Points.AddXY(...)之后,如果该系列的点数多于可显示的点数,请尝试调用series.Points.RemoveAt(0)。 每次新的出现时,这都会有效地弹出最旧的。

if(toolCapChart.Series["TOOL VOLTAGE"].Points.Count > maxSize)
    toolCapChart.Series["TOOL VOLTAGE"].Points.RemoveAt(0);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM