图的底部有一条线在使用zedgraph时连接最后一个点。我该如何删除?

时间:2012-03-04 15:23:51

标签: c# zedgraph

这是我的代码:

我正在尝试从文件夹中获取CSV文件。之后,我从这些文件中获取数据并将它们存储在zedX和zedY列表中。我将这两个数组传递给zedgraphControl。

我准确地得到了情节。但是,我的图表中有一条从0到最后一点的线性线。我该如何删除?

        //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();
        }

1 个答案:

答案 0 :(得分:1)

一个简单的逻辑错误。 zedX和zedY的长度必须只是thisbin.IndLists长度的一半,因为你交替赋值。因此曲线阵列的其余部分保持为零,因此曲线的最后几点为[0,0] 所以你必须这样做:

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

而不是:

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