c#画柱状图

http://blog.sina.com.cn/s/blog_50d936c40100djss.html###

 

这段时间要用C#做个项目,需要画一个曲线图,在网上找了半天资料都没找到合适的。不仅感叹C#和JAVA的区别。JAVA有很多开源项目,大大方便了其他人的使用。像在做统计图这一块,有就专门的JFreeChart组件,对于做统计图,十几行代码就搞定了。

  最后总算在一个网友提供的地址,才找到了一个别人做的比较好的源代码,粘贴如下:

 

柱状图的完整代码:

绘制柱状统计图的完整代码
private void CreateImage()
{
int height = 500, width = 700;
Bitmap image = new Bitmap(width, height);
//创建Graphics类对象
Graphics g = Graphics.FromImage(image);

try
{
//清空图片背景色
g.Clear(Color.White);

Font font = new Font("Arial", 10, FontStyle.Regular);
Font font1 = new Font("宋体", 20, FontStyle.Bold);

LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height),
Color.Blue, Color.BlueViolet, 1.2f, true);
g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);
// Brush brush1 = new SolidBrush(Color.Blue);

g.DrawString(this.ddlTaget.SelectedItem.Text + " " + this.ddlYear.SelectedItem.Text +
" 成绩统计柱状图", font1, brush, new PointF(70, 30));
//画图片的边框线
g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);


Pen mypen = new Pen(brush, 1);
//绘制线条
//绘制横向线条
int x = 100;
for (int i = 0; i < 14; i++)
{
g.DrawLine(mypen, x, 80, x, 340);
x 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值