程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 基本教程篇--第三節、第四節(2)

基本教程篇--第三節、第四節(2)

編輯:關於C語言

代碼如下:

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", "SpainnMadrid", "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軸。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved