无法在C#中为ZedGraph添加曲线

时间:2011-04-15 08:18:40

标签: c# zedgraph

我尝试使用ZedGraph添加多条曲线和yaxises。但是在我尝试添加第二条曲线后,我成功地在第一条曲线上添加了点数。第一个值'消失了 myCurve.Points.Count等于0.例如,如果我添加6条曲线,则只有第六条曲线具有其他值= 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();

错误在哪里?

1 个答案:

答案 0 :(得分:2)

您不会相互添加曲线,而是将它们添加到myPane.CurveList,以便将它们放在myPane.CurveList [0],myPane.CurveList [1]等等,而不是myCurve中。 myCurve用作您正在使用的当前曲线的商店。当你打电话

myCurve = myPane.AddCurve(ff.columnNames[k + 3], tempPointPairList, colors[k], SymbolType.None);

创建一条全新的曲线,添加到myPane.CurveList并写入myCurve变量。它刚刚创建时具有新鲜状态。您可以在myPane.CurveList中访问以前的曲线。