官网下载地址 http://sourceforge.net/projects/zedgraph/files/
在控件库中添加ZedGraph控件
右键点击工具箱 - 选择项 - .Net Framework 组件 - 浏览 - 找到ZedGraph.dll 和ZedGraph.Web.dll添加
zedGraphControl 控件就出现在工具箱中
public Form1()
{
InitializeComponent();
createPane(zedGraphControl1);
}
public void createPane(ZedGraphControl zgc)
{
GraphPane myPane = zgc.GraphPane;
//设置图标标题和x、y轴标题
myPane.Title.Text = "机票波动情况";
myPane.XAxis.Title.Text = "波动日期";
myPane.YAxis.Title.Text = "机票价格";
//更改标题的字体
FontSpec myFont = new FontSpec("Arial", 20, Color.Red, false, false, false);
myPane.Title.FontSpec = myFont;
myPane.XAxis.Title.FontSpec = myFont;
myPane.YAxis.Title.FontSpec = myFont;
// 造一些数据,PointPairList里有数据对x,y的数组
Random y = new Random();
PointPairList list1 = new PointPairList();
for (int i = 0; i < 36; i++)
{
double x = i;
//double y1 = 1.5 + Math.Sin((double)i * 0.2);
double y1 = y.NextDouble() *1000;
list1.Add(x, y1); //添加一组数据
}
// 用list1生产一条曲线,标注是“东航”
LineItem myCurve = myPane.AddCurve("东航",list1, Color.Red,SymbolType.Star);
//填充图表颜色
myPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f);
//以上生成的图标X轴为数字,下面将转换为日期的文本
string[] labels = new string[36];
for (int i = 0; i < 36; i++)
{
labels[i] = System.DateTime.Now.AddDays(i).ToShortDateString();
}
myPane.XAxis.Scale.TextLabels = labels; //X轴文本取值
myPane.XAxis.Type = AxisType.Text; //X轴类型
//画到zedGraphControl1控件中,此句必加
zgc.AxisChange();
//重绘控件
Refresh();
}
在图上点位标注数字的方法:
http://blog.csdn.net/dengta_snowwhite/archive/2011/01/12/6131265.aspx