开发者

Can't add curve to the ZedGraph in C#

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 and myCurve.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].Te开发者_运维知识库xt = 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?


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 call

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

a 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜