无法在 C# 中向 ZedGraph 添加曲线
我尝试使用 ZedGraph 添加多条曲线和 y 轴。但是在尝试添加第二条曲线后,我成功地将点添加到第一条曲线。第一个值'消失并且 myCurve.Points.Count
等于 0。例如,如果我添加 6 条曲线,则只有第六条曲线的值为 other count =0。它们中的任何一个也显示在图表上。代码如下:
colors = new Color[ff.documentColumnCount + 4];
zedGraphControl1.IsShowPointValues = true;
myPane = zedGraphControl1.GraphPane;
LineItem myCurve;
Color[] colors;
myPane.XAxis.Type = ZedGraph.AxisType.Date;
myPane.XAxis.Scale.Format = "HH:mm:ss";
myPane.XAxis.Scale.MajorUnit = DateUnit.Second;
zamanValue = new double[ff.tarihSaat.Length - 4]; // x axis time values. ff is another windows form name, no problem here.
for (int i = 0; i < ff.tarihSaat.Length - 4; i++)
{
zamanValue[i] = (double)new XDate(ff.tarihSaat[i].Year,
ff.tarihSaat[i].Month,
ff.tarihSaat[i].Day,
ff.tarihSaat[i].Hour,
ff.tarihSaat[i].Minute,
ff.tarihSaat[i].Second);
counter++;
}
yaxisArray = new YAxis[ff.documentColumnCount + 4]; // temp y axises
for (int k = 0; k < chckboxNumber; k++)
{
tempPointPairList.Clear();
tempPointPairList = createPairPointList(k); // Creates points, I see the correct values everytime, also no problem here.
minYvalues[k] = Findmin(tempPointPairList);
maxYvalues[k] = FindMax(tempPointPairList);
myCurve = myPane.AddCurve(ff.columnNames[k + 3], tempPointPairList, colors[k], SymbolType.None);
myCurve.Line.Width = 2.5f;
//myCurve.IsVisible = true;
myCurve.YAxisIndex = k;
myCurve.IsVisible = true;
if (k == 0)
{
myPane.YAxis.IsVisible = true;
myPane.YAxis.Scale.Max = 1;
myPane.YAxis.Scale.Min = 0;
myPane.YAxis.Scale.MajorStep = (myPane.YAxis.Scale.Max - myPane.YAxis.Scale.Min) / 10;
myPane.YAxis.MajorGrid.IsVisible = true;
}
else
{
yaxisArray[k] = new YAxis(ff.columnNames[k + 3]);
//yaxisArray[k].Color = colors[k];
yaxisArray[k].IsVisible = false;
yaxisArray[k].Title.IsVisible = false;
myPane.YAxisList.Add(yaxisArray[k]);
if (minYvalues[k] == maxYvalues[k])
{
yaxisArray[k].Scale.Min = minYvalues[k] - 0.1;
yaxisArray[k].Scale.Max = maxYvalues[k] + 0.1;
}
else
{
yaxisArray[k].Scale.Min = minYvalues[k];
yaxisArray[k].Scale.Max = maxYvalues[k];
}
myPane.YAxisList.Add(yaxisArray[k]);
}
yAxisListIndexes[k] = myPane.YAxisList.Count-1;
minTextBoxes[k].Text = minYvalues[k].ToString();
maxTextBoxes[k].Text = maxYvalues[k].ToString();
durum[k].previousState = 1;
durum[k].currentState = 1;
chckBoxList[k].Checked = true;
myCurve.Clear();
}
myPane.XAxis.Scale.Min = zamanValue[0];
myPane.XAxis.Scale.Max = zamanValue[zamanValue.Length - 1];
//myPane.YAxisList[0].IsVisible = true;
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();
zedGraphControl1.Refresh();
错误在哪里?
I try to add multiple curves and yaxises using ZedGraph. But I added points to the first curve succesfully after I tried to add the second curve. The first one values' disappear andmyCurve.Points.Count
equals 0. For example, if I add 6 curves, only the sixth one has values others count =0. Also any of them show up on the graph. Here is the code:
colors = new Color[ff.documentColumnCount + 4];
zedGraphControl1.IsShowPointValues = true;
myPane = zedGraphControl1.GraphPane;
LineItem myCurve;
Color[] colors;
myPane.XAxis.Type = ZedGraph.AxisType.Date;
myPane.XAxis.Scale.Format = "HH:mm:ss";
myPane.XAxis.Scale.MajorUnit = DateUnit.Second;
zamanValue = new double[ff.tarihSaat.Length - 4]; // x axis time values. ff is another windows form name, no problem here.
for (int i = 0; i < ff.tarihSaat.Length - 4; i++)
{
zamanValue[i] = (double)new XDate(ff.tarihSaat[i].Year,
ff.tarihSaat[i].Month,
ff.tarihSaat[i].Day,
ff.tarihSaat[i].Hour,
ff.tarihSaat[i].Minute,
ff.tarihSaat[i].Second);
counter++;
}
yaxisArray = new YAxis[ff.documentColumnCount + 4]; // temp y axises
for (int k = 0; k < chckboxNumber; k++)
{
tempPointPairList.Clear();
tempPointPairList = createPairPointList(k); // Creates points, I see the correct values everytime, also no problem here.
minYvalues[k] = Findmin(tempPointPairList);
maxYvalues[k] = FindMax(tempPointPairList);
myCurve = myPane.AddCurve(ff.columnNames[k + 3], tempPointPairList, colors[k], SymbolType.None);
myCurve.Line.Width = 2.5f;
//myCurve.IsVisible = true;
myCurve.YAxisIndex = k;
myCurve.IsVisible = true;
if (k == 0)
{
myPane.YAxis.IsVisible = true;
myPane.YAxis.Scale.Max = 1;
myPane.YAxis.Scale.Min = 0;
myPane.YAxis.Scale.MajorStep = (myPane.YAxis.Scale.Max - myPane.YAxis.Scale.Min) / 10;
myPane.YAxis.MajorGrid.IsVisible = true;
}
else
{
yaxisArray[k] = new YAxis(ff.columnNames[k + 3]);
//yaxisArray[k].Color = colors[k];
yaxisArray[k].IsVisible = false;
yaxisArray[k].Title.IsVisible = false;
myPane.YAxisList.Add(yaxisArray[k]);
if (minYvalues[k] == maxYvalues[k])
{
yaxisArray[k].Scale.Min = minYvalues[k] - 0.1;
yaxisArray[k].Scale.Max = maxYvalues[k] + 0.1;
}
else
{
yaxisArray[k].Scale.Min = minYvalues[k];
yaxisArray[k].Scale.Max = maxYvalues[k];
}
myPane.YAxisList.Add(yaxisArray[k]);
}
yAxisListIndexes[k] = myPane.YAxisList.Count-1;
minTextBoxes[k].Text = minYvalues[k].ToString();
maxTextBoxes[k].Text = maxYvalues[k].ToString();
durum[k].previousState = 1;
durum[k].currentState = 1;
chckBoxList[k].Checked = true;
myCurve.Clear();
}
myPane.XAxis.Scale.Min = zamanValue[0];
myPane.XAxis.Scale.Max = zamanValue[zamanValue.Length - 1];
//myPane.YAxisList[0].IsVisible = true;
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();
zedGraphControl1.Refresh();
Where is the mistake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无需将曲线相互添加,而是将它们添加到
myPane.CurveList
中,这样您就可以将它们放在 myPane.CurveList[0]、myPane.CurveList[1] 等中,而不是在 myCurve 中。 myCurve 用作您正在使用的当前曲线的存储。当您调用时,将创建一条全新的曲线,将其添加到 myPane.CurveList 并写入 myCurve 变量中。它具有刚刚创建时的新鲜状态。您可以在 myPane.CurveList 中访问以前的曲线。
You don't add curves to each other, you add them to
myPane.CurveList
so you have them in myPane.CurveList[0], myPane.CurveList[1] and so on, not in myCurve. myCurve serves as store for current curve you are working with. When you calla brand new curve is created, added to
myPane.CurveList
and is written into myCurve variable. It has a fresh state as it's just created. You can access your previous curve(s) in myPane.CurveList.