删除 ZedGraph 上的 GraphCurve 列表

Remove GraphCurve list on ZedGraph

我是 C# 的新手,正在尝试创建 lessor 传感器的 zedgraph。 首先,我创建一个全局变量并为图形编写代码。我的图表正在工作,但在到达 x 轴的 100 点后,它将与旧线重叠。 z1.GraphPane.CurveList.Clear();命令不起作用。我试过 listPointsOne.clear();命令也可以,但会清除该行并且不会在图形上显示任何内容。这个你能帮我吗。 我的代码如下:

        string DatafromCOM;
        double[] x = new double[100];
        double[] y = new double[100];
        int i;
        PointPairList listPointsOne = new PointPairList();
 private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            try
            {
                while (serialPort1.BytesToRead > 0)
                {
                    DatafromCOM = serialPort1.ReadLine();
                    double iData;
                    var ok = double.TryParse(txtKQ.Text, out iData);
                    if (DatafromCOM.Trim() != "" && ok)
                    {
                        i= (i + 1) % 100;
                        x[i] = i;
                        y[i] = iData;
                        listPointsOne.Add(i,iData);

                    }
                }

            }
            catch { }
        }
 private void timer1_Tick(object sender, EventArgs e)
        {
                z1.GraphPane.CurveList.Clear();
                z1.GraphPane.AddCurve(null, listPointsOne, Color.Red, SymbolType.None);
                z1.AxisChange();
                z1.Invalidate();
        }

你应该清除曲线列表

string DatafromCOM;
        double[] x = new double[100];
        double[] y = new double[100];
        int i;
        PointPairList listPointsOne = new PointPairList();
 private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            try
            {
                while (serialPort1.BytesToRead > 0)
                {
                    DatafromCOM = serialPort1.ReadLine();
                    double iData;
                    var ok = double.TryParse(txtKQ.Text, out iData);
                    if (DatafromCOM.Trim() != "" && ok)
                    {
                        i= (i + 1) % 100;
                        x[i] = i;
                        y[i] = iData;
                        listPointsOne.Add(i,iData);

                    }
                    z1.GraphPane.CurveList.Clear(); // Change here
                }

            }
            catch { }
        }



private void timer1_Tick(object sender, EventArgs e)
    {

            z1.GraphPane.AddCurve(null, listPointsOne, Color.Red, SymbolType.None);
            z1.AxisChange();
            z1.Invalidate();
    }