moose333 0 Light Poster

Hello

I'm having a few problems with trying to draw and then remove a line from a line graph.
I currently have been able to get the graph drawing using Zedgraph and plot the desired results.

The probelm I'm having is I now want to turn the plotted line on and off when a check box is checked and unchecked.

this is the code:

private void CreateGraph(ZedGraphControl zgc)
        {
            
            zedGraphControl1.Refresh();

            GraphPane myPane = zgc.GraphPane;


            myPane.Title.Text = "Cycle Graph";
            myPane.XAxis.Title.Text = "Time";
            myPane.YAxis.Title.Text = "Data";


            double x, y1, y2, y3, y4, y5, y6;
            PointPairList list1 = new PointPairList();

            for (int i = 0; i < myArr1.Length; i++)
            {
                x = (double)i + 2;

                y1 = col1[i];

                list1.Add(x, y1);

            }


            if (hrline.Checked == true)
            {
                LineItem myCurve = myPane.AddCurve("Heart Rate",
                      list1, Color.Red, SymbolType.Diamond);
                
            }

            else if (hrline.Checked == false)
            {
                myPane.CurveList.Remove(myCurve);
            }

            zgc.AxisChange();
        }

        private void hrline_CheckedChanged(object sender, EventArgs e)
        {
            CreateGraph(zedGraphControl1);
        }

Currently the graph draws the line when the checkbox is checked but then after a split second it is removed straight away.

Any help would be much appreciated.

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.