简体   繁体   English

同一zedgraph图上的多条曲线

[英]Multiple curves on Same zedgraph plot

I am trying to read in data from two serial ports, and plot each curve over time, on the same graph. 我正在尝试从两个串行端口读取数据,并在同一张图表上绘制随时间变化的每条曲线。 However, when I do this, it connects the curves. 但是,当我这样做时,它会连接曲线。 How do I keep the two data sets separate but on the same graph? 如何将两个数据集分开但在同一张图上? I've seen a lot of solutions using masterPane, however, when I try to use it, my program says that there is no materpane in zedgraph. 我已经看到了很多使用masterPane的解决方案,但是,当我尝试使用masterPane时,我的程序说zedgraph中没有materpane。

Here is the relevant code: 以下是相关代码:

GraphPane myPane2;
PointPairList Oz1time = new PointPairList();

myPane2 = zedGraphControl2.GraphPane;
myPane2.Title = "Data vs Time Plots";
myPane2.XAxis.Title = "Elapsed Minutes";
myPane2.YAxis.Title = "Ozone Data";

        private void UpdateData3(string line)
    {
        if (this.InvokeRequired)
        {
            this.BeginInvoke(new UpdateDataDelegate(UpdateData3), new object[] { line });
        }
        else
        {
            if (chk_DISPLAY_3.Checked == true)
            {
                timer3.Interval = (30000);
                timer3.Start();
                OZ1lastdatatime = DateTime.Now;
                count++;
                if (count > 7)
                {
                    count = 0;
                    TextBox_3.Text = "";
                    TextBox_3.AppendText(line);
                }
                else
                {
                    TextBox_3.AppendText(line);
                }
            }
            if (chk_SAVE_FILE_3.Checked == true)
            {
                StoreData3.Write(line);
                StoreData3.Flush();
            }
            if (chk_PLOT_1.Checked == true)
            {
                string[] blahArray = line.Split(new char[] { ',' });
                //string blaharray = Convert.ToDouble(blahArray[2]).ToString("F4");
                int column_data = Convert.ToInt32(textBox3.Text);
                double oz1 = Convert.ToDouble(blahArray[column_data]);
                //TextBox_3.Text = Convert.ToString(oz1);
                TimeSpan span = DateTime.UtcNow - startDateTimeOfProgram;
                double elapsedMinutes = span.TotalMinutes;

                Oz1time.Add(elapsedMinutes,oz1);
                zedGraphControl2.AxisChange();
                zedGraphControl2.GraphPane.AddCurve("", Oz1time , Color.Blue);
                zedGraphControl2.Refresh();



            }
        }
    }

   private void UpdateData4(string line)
    {
        if (this.InvokeRequired)
        {
            this.BeginInvoke(new UpdateDataDelegate(UpdateData4), new object[] { line });
        }
        else
        {
            Console.WriteLine(line);
            if (chk_DISPLAY_4.Checked == true)
            {
                timer4.Interval = (30000);
                timer4.Start();
                OZ2lastdatatime = DateTime.Now;
                count++;
                if (count > 7)
                {
                    count = 0;
                    TextBox_4.Text = "";
                    TextBox_4.AppendText(line);
                }
                else
                {
                    TextBox_4.AppendText(line);
                }
            }
            if (chk_SAVE_FILE_4.Checked == true)
            {
                StoreData4.Write(line);
                StoreData4.Flush();
            }
            if (chk_PLOT_2.Checked == true)
            {
                string[] blahArray = line.Split(new char[] { ',' });
                //string blaharray = Convert.ToDouble(blahArray[2]).ToString("F4");
                int column_data = Convert.ToInt32(textBox4.Text);
                double oz2 = Convert.ToDouble(blahArray[column_data]);
                //TextBox_3.Text = Convert.ToString(oz1);
                TimeSpan span = DateTime.UtcNow - startDateTimeOfProgram;
                double elapsedMinutes = span.TotalMinutes;

                Oz1time.Add(elapsedMinutes, oz2);
                zedGraphControl2.AxisChange();
                zedGraphControl2.GraphPane.AddCurve("", Oz1time, Color.Green);
                zedGraphControl2.Refresh();
            }
        }
    }

The main problem appears to be that you are using the same PointPairList , Oz1time , to create both curves. 主要问题似乎是您使用相同的PointPairList Oz1time创建两条曲线。 Instead, try creating two separate PointPairList s, one for each curve. 相反,尝试创建两个单独的PointPairList ,每个曲线一个。

Some relevant code bits: 一些相关的代码位:

PointPairList Oz2time = new PointPairList();
...
Oz2time.Add(elapsedMinutes, oz2);
...
zedGraphControl2.GraphPane.AddCurve("", Oz2time, Color.Green);

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

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