第一节:InitialSampleDemo.cs介绍
        为了讲解方便,我先附上源代码和效果图。
代码如下:
using System;
using System.Drawing;
using System.Collections;
 
using ZedGraph;
 
namespace ZedGraph.Demo
{
     ///<summary>
     /// Summary description for SimpleDemo.
     ///</summary>
     public class InitialSampleDemo : DemoBase
     {
 
           public InitialSampleDemo() : base(
"Code Project Initial Sample",
                "Initial Sample", DemoType.Tutorial )
           {
                GraphPane myPane = base.GraphPane;
 
                // Set the title and axis labels
                myPane.Title = "My Test Graph/n(For CodeProject Sample)";
                myPane.XAxis.Title = "My X Axis";
                myPane.YAxis.Title = "My Y Axis";
               
                // Make up some data arrays based on the Sine function
                PointPairList list1 = new PointPairList();
                PointPairList list2 = new PointPairList();
                for ( int i=0; i<36; i++
)
                {
                     double x = (double)
i + 5;
                     double y1 = 1.5 + Math.Sin( (double)
i * 0.2 );
                     double y2 = 3.0 * ( 1.5 + Math.Sin( (double)
i * 0.2 ) );
                     list1.Add( x, y1 );
                     list2.Add( x, y2 );
                }
 
                // Generate a red curve with diamond
                // symbols, and "Porsche" in the legend
                LineItem myCurve = myPane.AddCurve( "Porsche",
                     list1, Color.Red, SymbolType.Diamond );
 
                // Generate a blue curve with circle
                // symbols, and "Piper" in the legend
                LineItem myCurve2 = myPane.AddCurve( "Piper",
                     list2, Color.Blue, SymbolType.Circle );
 
                base.ZedGraphControl.AxisChange();
           }
     }
}
 
        我们可以看到,InitialSampleDemo继承自CemoBase类,而DemoBase又继承自ZedGraphDemo这个接口。ZedGraphDemo接口定义了String Description、String Title、ZedGraph. ZedGraphControl ZedGraphControl 和 System.Collection.ICollection Types这四个属性。DemoBase除了实现这四个属性外,还添加了PaneBase Pane和MasterPane
MasterPane这两个属性,此外DemoBase还实现了多载构造函数。关于各个类的具体含义和用法,我会在以后的篇幅中陆续介绍。这里只是给大家一个整体的大致结构。
        下面进行对代码的分析,由于这是第一个例子,所有我会讲得比较细,以后的例子就不会了。
        我们可以看到程序首先
public InitialSampleDemo() : base( "Code Project Initial Sample" , "Initial Sample", DemoType.Tutorial
)
初始化基类的构造函数。基类重载了四个构造函数
public DemoBase( string description, string title, DemoType type )
           {
                ArrayList types = new ArrayList();
                types.Add( type );
 
                Init( description, title, types );
           }
          
           public DemoBase( string description, string title,
DemoType type, DemoType type2 )
           {
                ArrayList types = new ArrayList();
                types.Add( type );
                types.Add( type2 );
 
                Init( description, title, types );
           }
          
           public DemoBase( string description, string title,
ICollection types )
           {
                Init( description, title, types );
           }
          
           private void Init( string description, string title,
ICollection types )
           {
                this.description = description;
                this.title = title;
                this.types = types;
 
                control = new ZedGraphControl();
           }
函数中的变量含义如下:
Description:对此结构的描述。
Title:在树形结构(TreeView)中显示的标题。
Types:要把此类显示在哪个树形结构的区域中。若有多个Types,则把此类分入不同的树形区域中。例如MasterPane Sample在Tutorial Sample和 Special Features两个区域都有。见图中的相应区域标注。
                        myPane.Title = "My Test Graph/n(For CodeProject Sample)";
                myPane.XAxis.Title = "My X Axis";
                myPane.YAxis.Title = "My Y Axis";
     分别指定这个Pane的title、XAxis和YAxis的标题。见上图。
 
                PointPairList list1 = new PointPairList();
                PointPairList list2 = new PointPairList();
                for ( int i=0; i<36; i++
)
                {
                     double x = (double)
i + 5;
                     double y1 = 1.5 + Math.Sin( (double)
i * 0.2 );
                     double y2 = 3.0 * ( 1.5 + Math.Sin( (double)
i * 0.2 ) );
                     list1.Add( x, y1 );
                     list2.Add( x, y2 );
                }
        PointPairList类是一个集合类,继承自
                                                        System.ObjectSystem.Collections.CollectionBaseZedGraph.CollectionPlus
它是PointPair对象的集合,PointPair类是一个包含(X,Y)的坐标类。
其中的for循环在为两个PointPairList复值。
 
LineItem myCurve = myPane.AddCurve( "Porsche", list1, Color.Red, SymbolType.Diamond );
LineItem类是ZedGraph中的线条类.
myPane.AddCurve( "Porsche", list1, Color.Red, SymbolType.Diamond );
的意思是将刚刚赋值的list以”Porsche”这个名字以红色和水晶形状画到Pane中,这个函数的返回值是一个LineItem。你可以通过myCurve这个变量来对它进行进一步的设定。其中SymbolType是个Enum,它枚举了12个可供使用的形状
 
最后一步就是刷新了。base.ZedGraphControl.AxisChange();
这样整个程序就完成了,简单吧,其实这是个简单的应该,以后会介绍更加复杂的用法和类库。

最新文章

  1. 还记得高中的向量吗?leetcode 335. Self Crossing(判断线段相交)
  2. java判断身份证有效性
  3. The Unique MST(次小生成树)
  4. js获取屏幕大小
  5. toStirng()与Object.prototype.toString.call()方法浅谈
  6. 用window.showModelDialog() 打开的页面的返回值
  7. 10条现代EQ技术基础贴士(转)
  8. AchartEngine绘图引擎
  9. bootstrap中datetimepicker只选择月份显示1899问题
  10. 优秀的富文本编辑器 Kindeditor
  11. js 高级函数 之示例
  12. IIs工作原理
  13. Keil中LIB库的作用、生成与调用
  14. C# 委托Delegate的使用 笔记
  15. Spring Cloud 微服务
  16. 记录一下msf的学习使用
  17. github 访问速度太慢
  18. # bzoj2215: [Poi2011]Conspiracy 2-sat
  19. vi 基本命令使用
  20. Robotframework(3):使用pycharm编写和运行RF脚本

热门文章

  1. EditText实现输入限制和校验
  2. yii2:如果获取config/web.php配置的值?
  3. [转]HTTP协议通信原理
  4. Android进阶常用网站
  5. C++多态、虚函数、纯虚函数、抽象类
  6. asp.net获取URL和IP地址
  7. Fiddler工作原理与代理设置
  8. 【tensorflow:Google】一、深度学习简介
  9. SVN 的搭建及使用(二)VisualSVN Server建立版本库,以及VisualSVN和TortoiseSVN的使用
  10. C#中upd分包与发送,已经实现全部代码