Unable to Plot Serial Data on Y2 Axis Zedgraph

586 views Asked by At

I am making a GUI that reads in serial data, and I want to have the option to choose to plot the data on either the left or right Y axis. I can plot the data on the left y axis, but I am unable to plot it on the Left axis. What is wrong with my code?

Here is the relevant Code:

GraphPane myPane2;
PointPairList inst3time = new PointPairList();
myPane2 = zedGraphControl2.GraphPane;
myPane2.Title = "Data vs Time Plots";
myPane2.XAxis.Title = "Elapsed Minutes";
       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_3.Checked == true)
            {
                string[] blahArray = line.Split(new char[] { ',' });
                //string blaharray = Convert.ToDouble(blahArray[2]).ToString("F4");
                int column_data = Convert.ToInt32(textBox5.Text);
                double inst3 = Convert.ToDouble(blahArray[column_data]);
                //TextBox_3.Text = Convert.ToString(oz1);
                TimeSpan span = DateTime.UtcNow - startDateTimeOfProgram;
                double elapsedMinutes = span.TotalMinutes;

                inst3time.Add(elapsedMinutes,inst3);
                if (cbo_POSITION_3.Text == "LEFT")
                {
                    myPane2.YAxis.Title = cbo_Instrument_3.Text;
                    zedGraphControl2.AxisChange();
                    zedGraphControl2.GraphPane.AddCurve("",inst3time, Color.Blue, SymbolType.Circle);
                    zedGraphControl2.Refresh();
                }
                if (cbo_POSITION_3.Text == "RIGHT")
                {
                    myPane2.Y2Axis.Title = cbo_Instrument_3.Text;
                    zedGraphControl2.AxisChange();
                    LineItem myCurve = zedGraphControl2.GraphPane.AddCurve("",inst3time, Color.Blue, SymbolType.Circle);
                    myCurve.IsY2Axis = true;
                    zedGraphControl2.Refresh();
      }
    }
  }
}
1

There are 1 answers

0
manateejoe On BEST ANSWER

I was able to figure it out: I needed to make sure that the Y2 Axis was visible:

 myPane2.Y2Axis.IsVisible = true;
 myPane2.Y2Axis.Title = cbo_Instrument_3.Text;
 zedGraphControl2.AxisChange();
 LineItem myCurve = myPane2.AddCurve("",inst3time, Color.Blue, SymbolType.Circle);
 myCurve.IsY2Axis = true;
 zedGraphControl2.AxisChange();
 zedGraphControl2.Refresh();