无法在 Y2 轴 Zedgraph 上绘制串行数据

Unable to Plot Serial Data on Y2 Axis Zedgraph

我正在制作一个读取串行数据的 GUI,我希望可以选择在左 Y 轴或右 Y 轴上绘制数据。我可以在左 y 轴上绘制数据,但无法在左轴上绘制数据。我的代码有什么问题?

相关代码如下:

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

我弄明白了:我需要确保 Y2 轴可见:

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