用C# and GDI+画柱状图(可以从数据库里导出数据画)
晚上归来,匆忙画出下图,变量命名简简单单取的.图如下:
public void Bind()
{
//创建一个画布
Bitmap bm=new Bitmap(240,210);
//在新建的画布上画一个图
Graphics bp=Graphics.FromImage(bm);
//设置bp的背景色为Beige
bp.Clear(Color.Beige);
//创建数据源,在此为一个数组
int [] a1={20,40,60,80,100,120,140,160};
int [] a2={40,60,80,100,120,140,160,180};
bp.DrawRectangle(Pens.Black,1,1,230,205);
//通过循环画出柱状图
for(int i=0;i<a1.Length;i++)
{
//填充图(着色,起点X,起点Y,宽,高)
bp.FillRectangle(new SolidBrush(Color.Blue),(i*30)+5,200-a1[i],5,a1[i]+5);
//填充边框(着色,起点X,起点Y,宽,高)
bp.DrawRectangle(Pens.Black,(i*30)+5,200-a1[i],5,a1[i]+5);
}
//柱图2
for(int i=0;i<a2.Length;i++)
{
bp.FillRectangle(new SolidBrush(Color.Red),(i*30)+10,200-a2[i],5,a2[i]+5);
bp.DrawRectangle(Pens.Black,(i*30)+10,200-a2[i],5,a2[i]+5);
}
//以gif格式输出到IE上
bm.Save(Response.OutputStream,ImageFormat.Gif);
}
{
//创建一个画布
Bitmap bm=new Bitmap(240,210);
//在新建的画布上画一个图
Graphics bp=Graphics.FromImage(bm);
//设置bp的背景色为Beige
bp.Clear(Color.Beige);
//创建数据源,在此为一个数组
int [] a1={20,40,60,80,100,120,140,160};
int [] a2={40,60,80,100,120,140,160,180};
bp.DrawRectangle(Pens.Black,1,1,230,205);
//通过循环画出柱状图
for(int i=0;i<a1.Length;i++)
{
//填充图(着色,起点X,起点Y,宽,高)
bp.FillRectangle(new SolidBrush(Color.Blue),(i*30)+5,200-a1[i],5,a1[i]+5);
//填充边框(着色,起点X,起点Y,宽,高)
bp.DrawRectangle(Pens.Black,(i*30)+5,200-a1[i],5,a1[i]+5);
}
//柱图2
for(int i=0;i<a2.Length;i++)
{
bp.FillRectangle(new SolidBrush(Color.Red),(i*30)+10,200-a2[i],5,a2[i]+5);
bp.DrawRectangle(Pens.Black,(i*30)+10,200-a2[i],5,a2[i]+5);
}
//以gif格式输出到IE上
bm.Save(Response.OutputStream,ImageFormat.Gif);
}
阿里云优惠券领取地址:https://partner.aliyun.com/shop/35783975 ,需要更多优惠请联系QQ和微信:891115,热线:400-968-4968