我正在制作一个读取串行数据的GUI,我希望可以选择在左或右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();
}
}
}
}
答案 0 :(得分:0)
我能够弄明白:我需要确保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();