0

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.

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();
            }
        }
    }
John Saunders
  • 160,644
  • 26
  • 247
  • 397
manateejoe
  • 344
  • 2
  • 6
  • 19

1 Answers1

1

The main problem appears to be that you are using the same PointPairList, Oz1time, to create both curves. Instead, try creating two separate PointPairLists, one for each curve.

Some relevant code bits:

PointPairList Oz2time = new PointPairList();
...
Oz2time.Add(elapsedMinutes, oz2);
...
zedGraphControl2.GraphPane.AddCurve("", Oz2time, Color.Green);
adv12
  • 8,443
  • 2
  • 24
  • 48
  • Thank you! How come c# doesn't recognize the masterpane command? I'm also trying to is OZ1time.IsY2Axis = true; to add another y axis, however c# says that IsY2Axis doesn't exist – manateejoe Jun 15 '15 at 20:09
  • I know nothing about "masterpane". About the Y axis, you first need to create one, like this: `int idx = zedGraphControl2.GraphPane.AddY2Axis("Other Stuff")`; – adv12 Jun 15 '15 at 20:14
  • Thanks for the help, for some reason visual studio doesn't recognize the commands: IsY2Axis or AddY2Axis – manateejoe Jun 15 '15 at 20:28