GDI绘图


public void draw(Page page,DataTable dt,int Tnum)
{
//取得记录数量
int count = dt.Rows.Count;
//记算图表宽度
int wd = 80 + 20 * (count - 1);
//设置最小宽度为800
if (wd < 800) wd = 800;
//生成Bitmap对像
Bitmap img=new Bitmap(wd,400);
//生成绘图对像
Graphics g = Graphics.FromImage(img);
//定义黑色画笔
Pen Bp = new Pen(Color.Black);
//定义红色画笔
Pen Rp = new Pen(Color.Red);
//定义银灰色画笔
Pen Sp = new Pen(Color.Silver);
//定义大标题字体
Font Bfont = new Font("Arial", 12, FontStyle.Bold);
//定义一般字体
Font font = new Font("Arial", 6);
//定义大点的字体
Font Tfont = new Font("Arial", 9);
//绘制底色
g.DrawRectangle(new Pen(Color.White, 400), 0, 0, img.Width, img.Height);
//定义黑色过渡型笔刷
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Black, Color.Black, 1.2F, true);
//定义蓝色过渡型笔刷
LinearGradientBrush Bluebrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Blue, Color.Blue, 1.2F, true);
//绘制大标题
g.DrawString(dt.Rows[0]["Num"].ToString() + "本年慢病随访情况曲线图", Bfont, brush, 40, 5);
//取得当前发送量
int nums=0;
for (int i = 0; i < count; i++)
{
nums += Convert.ToInt32(dt.Rows[i]["Num"]);
}
//绘制信息简报
string info="首次随访时间:"+dt.Rows[0]["dc"].ToString()+" 曲线图生成时间:"+DateTime.Now.ToString()+" 随访次数:"+dt.Rows.Count.ToString()+" 当前发送总量:"+nums.ToString();
g.DrawString(info, Tfont, Bluebrush, 40, 25);
//绘制图片边框
g.DrawRectangle(Bp, 0, 0, img.Width - 1, img.Height - 1);

//绘制竖坐标线
for (int i = 0; i < count; i++)
{
g.DrawLine(Sp, 40+20 * i, 60, 40+20 * i, 360);
}

//绘制时间轴坐标标签
for (int i = 0; i < count; i+=2)
{
string st = Convert.ToDateTime(dt.Rows[i]["dc"]).ToString("yyyy-MM-dd");
g.DrawString(st, font, brush, 30 + 20 * i, 370); }
//绘制横坐标线
for (int i = 0; i < 10; i++)
{
g.DrawLine(Sp, 40, 60+30*i, 40+20*(count-1), 60+30*i);
int s = 2500 - 50 * i * 5;
//绘制发送量轴坐标标签
g.DrawString(s.ToString(), font, brush, 10, 60 + 30 * i);
}

//绘制竖坐标轴
g.DrawLine(Bp, 40, 55, 40, 360);
//绘制横坐标轴
g.DrawLine(Bp, 40, 360, 45 + 20 * (count - 1), 360);

//定义曲线转折点
Point[] p = new Point[count];
for (int i = 0; i < count; i++)
{
p[i].X = 40 + 20 * i;
p[i].Y = 360 - Convert.ToInt32(dt.Rows[i]["Num"]) / 5 * 3 / 5;
}
//绘制发送曲线
g.DrawLines(Rp, p);

for (int i = 0; i < count; i++)
{
//绘制发送记录点的发送量
g.DrawString(dt.Rows[i]["Num"].ToString(), font, Bluebrush, p[i].X, p[i].Y - 10);
//绘制发送记录点
g.DrawRectangle(Rp, p[i].X - 1, p[i].Y - 1, 2, 2);
}
//绘制竖坐标标题
g.DrawString("血压值", Tfont, brush, 5, 40);
//绘制横坐标标题
g.DrawString("随访时间", Tfont, brush, 40, 385);


//保存绘制的图片
MemoryStream stream = new MemoryStream();
img.Save(stream, ImageFormat.Jpeg);
//图片输出
page.Response.Clear();
page.Response.ContentType = "image/jpeg";
page.Response.BinaryWrite(stream.ToArray());
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值