Search code examples
c#graphplotlivezedgraph

ZedGraph Multiple panes


I am using ZedGraph. I have only one control containing three Panes. I initialize them like this:

    private void GraphIt()
    {
        MasterPane master = zedGraphControl1.MasterPane;
        master.PaneList.Clear();

        // Display the MasterPane Title, and set the outer margin to 10 points
        master.Title.IsVisible = true;
        master.Title.Text = "Angles";
        master.Margin.All = 10;

        // Create some GraphPane's (normally you would add some curves too
        GraphPane pane1 = new GraphPane();
        GraphPane pane2 = new GraphPane();
        GraphPane pane3 = new GraphPane();

        // Add all the GraphPanes to the MasterPane
        master.Add(pane1);
        master.Add(pane2);
        master.Add(pane3);

        pane1.XAxis.Scale.MinorStep = pane2.XAxis.Scale.MinorStep = pane3.XAxis.Scale.MinorStep = 1;
        pane1.XAxis.Scale.MajorStep = pane2.XAxis.Scale.MajorStep = pane3.XAxis.Scale.MajorStep = 50;

        PointPairList dummylist = new PointPairList();
        myCurve1 = pane1.AddCurve("Angle X", dummylist, Color.Red);
        myCurve2 = pane2.AddCurve("Angle Y", dummylist, Color.Blue);
        myCurve3 = pane3.AddCurve("Angle Z", dummylist, Color.Green);
        myCurve1.Line.Width = myCurve2.Line.Width = myCurve3.Line.Width = 5;
        myCurve1.Symbol.Size = myCurve2.Symbol.Size = myCurve3.Symbol.Size = 0;

        // Refigure the axis ranges for the GraphPanes
        zedGraphControl1.AxisChange();

        // Layout the GraphPanes using a default Pane Layout
        using (Graphics g = this.CreateGraphics())
        {
            master.SetLayout(g, PaneLayout.SquareColPreferred);
        }
    }

I want to draw live curves each in one pane. I add points during my program run and refresh the graph. Everything is perfect except that the points of each curve get added to the other curves too. Example:

myCurve1.AddPoint(Time, 10);
myCurve2.AddPoint(Time, 5);
myCurve3.AddPoint(Time, 1);

I do this to add my points. What happens is, on each curve the three points are added as if i did this:

myCurve1.AddPoint(Time, 10);
myCurve1.AddPoint(Time, 5);
myCurve1.AddPoint(Time, 1);

myCurve2.AddPoint(Time, 10);
myCurve2.AddPoint(Time, 5);
myCurve2.AddPoint(Time, 1);

myCurve3.AddPoint(Time, 10);
myCurve3.AddPoint(Time, 5);
myCurve3.AddPoint(Time, 1);

Solution

  • Change this:

    PointPairList dummylist = new PointPairList();
    myCurve1 = pane1.AddCurve("Angle X", dummylist, Color.Red);
    myCurve2 = pane2.AddCurve("Angle Y", dummylist, Color.Blue);
    myCurve3 = pane3.AddCurve("Angle Z", dummylist, Color.Green);
    

    to this:

    PointPairList dummylist = new PointPairList();
    myCurve1 = pane1.AddCurve("Angle X", dummylist, Color.Red);
    dummylist = new PointPairList();
    myCurve2 = pane2.AddCurve("Angle Y", dummylist, Color.Blue);
    dummylist = new PointPairList();
    myCurve3 = pane3.AddCurve("Angle Z", dummylist, Color.Green);