我的DOTNET

我就是咖啡豆

用ZedGraph作图表(二)

这一次创建一个bar图(代码取至ZedGraph的Demo)


public void CreateBar(ZedGraphControl zgc)
{
GraphPane myPane = zgc.GraphPane;

// 设置图表的说明文字
myPane.Title.Text = "Vertical Bars with Value Labels Above Each Bar";

// 设置横坐标的说明文字
myPane.XAxis.Title.Text = "Position Number";

// 设置纵坐标的说明文字
myPane.YAxis.Title.Text = "Some Random Thing";

PointPairList list = new PointPairList();
PointPairList list2 = new PointPairList();
PointPairList list3 = new PointPairList();
Random rand = new Random();

// Generate random data for three curves
for ( int i=0; i<5; i++ )
{
double x = (double) i;
double y = rand.NextDouble() * 1000;
double y2 = rand.NextDouble() * 1000;
double y3 = rand.NextDouble() * 1000;
list.Add( x, y );
list2.Add( x, y2 );
list3.Add( x, y3 );
}

// 创建每个bar
BarItem myCurve = myPane.AddBar( "curve 1", list, Color.Blue );
BarItem myCurve2 = myPane.AddBar( "curve 2", list2, Color.Red );
BarItem myCurve3 = myPane.AddBar( "curve 3", list3, Color.Green );

// 设置图标的颜色和渐变色
myPane.Chart.Fill = new Fill( Color.White,
Color.FromArgb( 255, 255, 166), 45.0F );

zgc.AxisChange();

// 创建每条bar的label,其中第2个参数表示是否显示在bar的中心位置,第3个参数表示label的排列方向
BarItem.CreateBarLabels( myPane, false, "f0" );
}

Technorati : ZedGraph作图表

posted on 2006-08-11 11:41  小小~咖啡豆  阅读(4785)  评论(0编辑  收藏  举报

导航