Multiple curves on Same zedgraph plot

1.9k views Asked by At

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

There are 1 answers

3
adv12 On BEST ANSWER

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