同一 zedgraph 图上的多条曲线
Multiple curves on Same zedgraph plot
我正在尝试从两个串口读取数据,并在同一张图上绘制每条随时间变化的曲线。但是,当我这样做时,它连接了曲线。如何将两个数据集分开但放在同一个图表上?我已经看到很多使用 masterPane 的解决方案,但是,当我尝试使用它时,我的程序说 zedgraph 中没有 materpane。
相关代码如下:
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();
}
}
}
主要问题似乎是您使用相同的 PointPairList
、Oz1time
来创建两条曲线。相反,尝试创建两个单独的 PointPairList
s,每条曲线一个。
一些相关代码位:
PointPairList Oz2time = new PointPairList();
...
Oz2time.Add(elapsedMinutes, oz2);
...
zedGraphControl2.GraphPane.AddCurve("", Oz2time, Color.Green);
我正在尝试从两个串口读取数据,并在同一张图上绘制每条随时间变化的曲线。但是,当我这样做时,它连接了曲线。如何将两个数据集分开但放在同一个图表上?我已经看到很多使用 masterPane 的解决方案,但是,当我尝试使用它时,我的程序说 zedgraph 中没有 materpane。
相关代码如下:
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();
}
}
}
主要问题似乎是您使用相同的 PointPairList
、Oz1time
来创建两条曲线。相反,尝试创建两个单独的 PointPairList
s,每条曲线一个。
一些相关代码位:
PointPairList Oz2time = new PointPairList();
...
Oz2time.Add(elapsedMinutes, oz2);
...
zedGraphControl2.GraphPane.AddCurve("", Oz2time, Color.Green);