zedgraph基本教程篇--第三节、第四节DateAxisSampleDemo.cs和TextAxisSampleDemo.cs介绍

zedgraph基本教程篇--第三节、第四节DateAxisSampleDemo.cs和TextAxisSampleDemo.cs介绍 

第三节、第四节DateAxisSampleDemo.cs和TextAxisSampleDemo.cs介绍      

        由于这两个例子很简单也很相似,所以决定还是放到一起来写。按照惯例还是先给出代码和图示。
zedgraph基本教程篇--第三节、第四节DateAxisSampleDemo.cs和TextAxisSampleDemo.cs介绍
 
    
      
代码如下:
DateAxisSampleDemo:
using System;
using System.Drawing;
using System.Collections;

using ZedGraph;

namespace ZedGraph.Demo
{
/// <summary>
/// Summary description for SimpleDemo.
/// </summary>
public class DateAxisSampleDemo : DemoBase
{

public DateAxisSampleDemo() : base ( " Code Project Date Axis Sample " ,
" Date Axis Sample " , DemoType.Tutorial )
{
GraphPane myPane
= base .GraphPane;

// Set the titles and axis labels
myPane.Title = " My Test Date Graph " ;
myPane.XAxis.Title
= " Date " ;
myPane.YAxis.Title
= " My Y Axis " ;

// Make up some data points based on the Sine function
PointPairList list = new PointPairList();
for ( int i = 0 ; i < 36 ; i ++ )
{
double x = ( double ) new XDate( 1995 , 5 , i + 11 );
double y = Math.Sin( ( double ) i * Math.PI / 15.0 );
list.Add( x, y );
}

// Generate a red curve with diamond
// symbols, and "My Curve" in the legend
LineItem myCurve = myPane.AddCurve( " My Curve " ,
list, Color.Red, SymbolType.Diamond );

// Set the XAxis to date type
myPane.XAxis.Type = AxisType.Date;

base .ZedGraphControl.AxisChange();
}
}
}

TextAxisSampleDemo:
using System;
using System.Drawing;
using System.Collections;

using ZedGraph;

namespace ZedGraph.Demo
{
/// <summary>
/// Summary description for SimpleDemo.
/// </summary>
public class TextAxisSampleDemo : DemoBase
{

public TextAxisSampleDemo() : base ( " Code Project Text Axis Sample " ,
" Text Axis Sample " , DemoType.Tutorial )
{
GraphPane myPane
= base .GraphPane;

// Set the title and axis labels
myPane.Title = " My Test Date Graph " ;
myPane.XAxis.Title
= " Label " ;
myPane.YAxis.Title
= " My Y Axis " ;

// Make up some data points
string [] labels = { " USA " , " Spain\nMadrid " , " Qatar " , " Morocco " , " UK " , " Uganda " ,
" Cambodia " , " Malaysia " , " Australia " , " Ecuador " };
double [] y = new double [ 10 ];
for ( int i = 0 ; i < 10 ; i ++ )
y[i]
= Math.Sin( ( double ) i * Math.PI / 2.0 );

// Generate a red curve with diamond
// symbols, and "My Curve" in the legend
LineItem myCurve = myPane.AddCurve( " My Curve " ,
null , y, Color.Red, SymbolType.Diamond );

// Make the curve smooth
myCurve.Line.IsSmooth = true ;

// Set the XAxis to Text type
myPane.XAxis.Type = AxisType.Text;
// Set the XAxis labels
myPane.XAxis.TextLabels = labels;
// Set the labels at an angle so they don't overlap
myPane.XAxis.ScaleFontSpec.Angle = 40 ;

base .ZedGraphControl.AxisChange();
}
}
}

看到前两节的介绍,这里的代码就应该很简单了,我要说的只有两个类XDate和TextLabel这个属性。
首先XDate就相当于msdn中的DateTime这个类,是个时间日期类,也是具有多个构造函数,XDate(
1995 , 5 , i + 11 )是按年月日来初始化的。
第二个就是TextLabel属性,它主要是把Label的内容显示在Pane上。如TextAxisSampleDemo的X轴。


本文来自CSDN博客,转载请标明出处:http:
// blog.csdn.net/tjvictor/archive/2006/11/25/1413781.aspx

你可能感兴趣的:(sample)