用zedgraph画简单2D图像的步骤

1.下载zedgraph.dll

2.添加zedgraph控件:打开工具栏右键单击,选择项->.Net Framework组件,浏览你下载的zedgraph.dll,点添加即可。zedgraph控件就出现在工具栏中。

3.把控件拖到form中

4.添加命名空间using zedgraph

5. Form1_Load中的代码如下:

 private void Form1_Load(object sender, EventArgs e)
        {
            GraphPane myPane = zedGraphControl1.GraphPane;
            // get a reference to the GraphPane  

            // Set the Titles 

            myPane.Title.Text  = "My Test Graph\n(For CodeProject Sample)";  //修改title
            myPane.XAxis.Title.Text  ="X 坐标";  //修改X坐标的显示
            myPane.YAxis.Title.Text  = "Y 坐标";  //修改Y坐标的显示

            double x, y1, y2;
            PointPairList list1 = new PointPairList();    //保存X.Y坐标
            PointPairList list2 = new PointPairList();
            for (int i = 0; i < 36; i++)
            {
                x = (double)i + 5;
                y1 = 1.5 + Math.Sin((double)i * 0.2); //正弦图形
                y2 = 3.0 * (1.5 + Math.Sin((double)i * 0.2));
                list1.Add(x, y1);
                list2.Add(x, y2);
            }  

            LineItem myCurve = myPane.AddCurve("Porsche", list1, Color.Red, SymbolType.Diamond);

            LineItem myCurve2 = myPane.AddCurve("Piper", list2, Color.Blue, SymbolType.Circle);

  
            zedGraphControl1.AxisChange();   //来调整X轴
            zedGraphControl1.Invalidate(); //使控件的整个图面无效并导致重绘控件
        }
    }

 

图片所示是运行后的图像截图:

 

你可能感兴趣的:(list,reference,graph,工具,object,图形)