基本教程篇--第三节、第四节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轴。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值