Search code examples
c#zedgraph

There is a line in the bottom part of the graph that joins the last point while using zedgraph. How can I remove this?


Here is my code:

I am trying to get the CSV files from a folder. After that, I fetch the data from these files and store them in zedX and zedY lists. I pass these two arrays into zedgraphControl.

I am getting the plot accurately. But, there is a linear line joining from 0 to the last point in my graph. How should I remove this?

        //I am taking in a folder which have CSV files containing a data. So, iterating over files in the outer loop
        for (int i = 0; i < inputFolder.Count; i++)
        {
            //Lists to contain the data
            List<Double> zedXList = new List<double>();
            List<Double> zedYList = new List<double>();

            //Arrays to be passed into zedgraph
            double[] zedX = new double[thisbin.IndLists[i].Count()];
            double[] zedY = new double[thisbin.IndLists[i].Count()];

            for (int l = 0; l < thisbin.IndLists[i].Count(); l++)
            {
                zedX[l] = 0;
                zedY[l] = 0;
            }
            //In the inner loop I fetch the data from the file and store it in lists
            for (int j = 0; j < thisbin.IndLists[i].Count(); j++)
            {
                if (j % 2 == 0)
                {
                    zedXList.Add(thisbin.IndLists[i][j]);
                }
                if (j % 2 != 0)
                {
                    zedYList.Add(thisbin.IndLists[i][j]);
                }
            }

            //from the lists I pass the data into arrays, in order to pass it into zedgraph
            for (int k = 0; k < zedXList.Count(); k++)
            {
                zedX[k] = Convert.ToDouble(zedXList[k]);
                zedY[k] = Convert.ToDouble(zedYList[k]);

            }

            //zedgraph plot
            string title = "PLOT-" + Convert.ToString(i + 1);
            TabPage myTabPage = new TabPage(title);
            var zed = new ZedGraphControl();
            zed.Dock = DockStyle.Fill;
            zed.Size = new System.Drawing.Size(575, 312);
            zed.GraphPane.CurveList.Clear();
            var Indpane2 = zed.GraphPane;
            Indpane2.Title.Text = "PLOT" + Convert.ToString(i + 1);
            Indpane2.XAxis.Title.Text = "m/z";
            Indpane2.YAxis.Title.Text = "Intensity";
            var ind2 = new PointPairList(zedX, zedY);
            var IndCurve2 = Indpane2.AddCurve(title, ind2, Color.OrangeRed, SymbolType.Default);
            Indpane2.AxisChange();

            myTabPage.Controls.Add(zed);
            tabControl1.TabPages.Add(myTabPage);

            IndCurve2.Line.IsVisible = true;
            IndCurve2.Line.Width = 2.0F;
            zed.Invalidate();
            zed.Refresh();
        }

Solution

  • A simple logical mistake. The lenght of zedX and zedY must be only the half of the length of thisbin.IndLists, because you alternate the assignment of the values. So the rest of your curve-arrays remains zero, so the last points of the curves are [0,0].
    So you have to do this:

    double[] zedX = new double[thisbin.IndLists[i].Count()/2];  
    double[] zedY = new double[thisbin.IndLists[i].Count()/2]; 
    

    instead of this:

    double[] zedX = new double[thisbin.IndLists[i].Count()];  
    double[] zedY = new double[thisbin.IndLists[i].Count()];`