asp.net生成曲线图实现代码
2023-06-13 09:14:08 时间
我的Dataset是从表Sendrec里读取的数据,分别有Id,Sendid(订单号),Sendtime(记录时间),Sendnum(单位时间发送量/我这里是五分钟)几个字段
过程如下:
publicvoiddraw(Pagepage,DataSetds,intTnum){}
其中page是用来传递引用这个过程的页面,这样让页面是JPG方式直接向客户端输出生成的曲线图.
ds就是取出来的数据集了
Tnum只是我这里要用到的一个参数,不想让这个类去接触读取过程,所以把订单的总量直接取出后传递给它的.
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;
usingSystem.Drawing.Drawing2D;
usingSystem.Drawing.Imaging;
usingSystem.Drawing;
usingSystem.IO;
publicclassimgdraw
{
publicimgdraw()
{
}
publicvoiddraw(Pagepage,DataSetds,intTnum)
{
//取得记录数量
intcount=ds.Tables[0].Rows.Count;
//记算图表宽度
intwd=80+20*(count-1);
//设置最小宽度为800
if(wd<800)wd=800;
//生成Bitmap对像
Bitmapimg=newBitmap(wd,400);
//生成绘图对像
Graphicsg=Graphics.FromImage(img);
//定义黑色画笔
PenBp=newPen(Color.Black);
//定义红色画笔
PenRp=newPen(Color.Red);
//定义银灰色画笔
PenSp=newPen(Color.Silver);
//定义大标题字体
FontBfont=newFont("Arial",12,FontStyle.Bold);
//定义一般字体
Fontfont=newFont("Arial",6);
//定义大点的字体
FontTfont=newFont("Arial",9);
//绘制底色
g.DrawRectangle(newPen(Color.White,400),0,0,img.Width,img.Height);
//定义黑色过渡型笔刷
LinearGradientBrushbrush=newLinearGradientBrush(newRectangle(0,0,img.Width,img.Height),Color.Black,Color.Black,1.2F,true);
//定义蓝色过渡型笔刷
LinearGradientBrushBluebrush=newLinearGradientBrush(newRectangle(0,0,img.Width,img.Height),Color.Blue,Color.Blue,1.2F,true);
//绘制大标题
g.DrawString(ds.Tables[0].Rows[0]["sendid"].ToString()+"号订单发送情况曲线图",Bfont,brush,40,5);
//取得当前发送量
intnums=0;
for(inti=0;i<count;i++)
{
nums+=Convert.ToInt32(ds.Tables[0].Rows[i]["sendnum"]);
}
//绘制信息简报
stringinfo="订单发送时间:"+ds.Tables[0].Rows[0]["sendtime"].ToString()+"曲线图生成时间:"+DateTime.Now.ToString()+"订单总量:"+Tnum.ToString()+"当前发送总量:"+nums.ToString();
g.DrawString(info,Tfont,Bluebrush,40,25);
//绘制图片边框
g.DrawRectangle(Bp,0,0,img.Width-1,img.Height-1);
//绘制竖坐标线
for(inti=0;i<count;i++)
{
g.DrawLine(Sp,40+20*i,60,40+20*i,360);
}
//绘制时间轴坐标标签
for(inti=0;i<count;i+=2)
{
stringst=Convert.ToDateTime(ds.Tables[0].Rows[i]["sendtime"]).ToString("hh:mm");
g.DrawString(st,font,brush,30+20*i,370);
}
//绘制横坐标线
for(inti=0;i<10;i++)
{
g.DrawLine(Sp,40,60+30*i,40+20*(count-1),60+30*i);
ints=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=newPoint[count];
for(inti=0;i<count;i++)
{
p[i].X=40+20*i;
p[i].Y=360-Convert.ToInt32(ds.Tables[0].Rows[i]["sendnum"])/5*3/5;
}
//绘制发送曲线
g.DrawLines(Rp,p);
for(inti=0;i<count;i++)
{
//绘制发送记录点的发送量
g.DrawString(ds.Tables[0].Rows[i]["sendnum"].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);
//保存绘制的图片
MemoryStreamstream=newMemoryStream();
img.Save(stream,ImageFormat.Jpeg);
//图片输出
page.Response.Clear();
page.Response.C;
page.Response.BinaryWrite(stream.ToArray());
}
}
过程如下:
publicvoiddraw(Pagepage,DataSetds,intTnum){}
其中page是用来传递引用这个过程的页面,这样让页面是JPG方式直接向客户端输出生成的曲线图.
ds就是取出来的数据集了
Tnum只是我这里要用到的一个参数,不想让这个类去接触读取过程,所以把订单的总量直接取出后传递给它的.
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;
usingSystem.Drawing.Drawing2D;
usingSystem.Drawing.Imaging;
usingSystem.Drawing;
usingSystem.IO;
publicclassimgdraw
{
publicimgdraw()
{
}
publicvoiddraw(Pagepage,DataSetds,intTnum)
{
//取得记录数量
intcount=ds.Tables[0].Rows.Count;
//记算图表宽度
intwd=80+20*(count-1);
//设置最小宽度为800
if(wd<800)wd=800;
//生成Bitmap对像
Bitmapimg=newBitmap(wd,400);
//生成绘图对像
Graphicsg=Graphics.FromImage(img);
//定义黑色画笔
PenBp=newPen(Color.Black);
//定义红色画笔
PenRp=newPen(Color.Red);
//定义银灰色画笔
PenSp=newPen(Color.Silver);
//定义大标题字体
FontBfont=newFont("Arial",12,FontStyle.Bold);
//定义一般字体
Fontfont=newFont("Arial",6);
//定义大点的字体
FontTfont=newFont("Arial",9);
//绘制底色
g.DrawRectangle(newPen(Color.White,400),0,0,img.Width,img.Height);
//定义黑色过渡型笔刷
LinearGradientBrushbrush=newLinearGradientBrush(newRectangle(0,0,img.Width,img.Height),Color.Black,Color.Black,1.2F,true);
//定义蓝色过渡型笔刷
LinearGradientBrushBluebrush=newLinearGradientBrush(newRectangle(0,0,img.Width,img.Height),Color.Blue,Color.Blue,1.2F,true);
//绘制大标题
g.DrawString(ds.Tables[0].Rows[0]["sendid"].ToString()+"号订单发送情况曲线图",Bfont,brush,40,5);
//取得当前发送量
intnums=0;
for(inti=0;i<count;i++)
{
nums+=Convert.ToInt32(ds.Tables[0].Rows[i]["sendnum"]);
}
//绘制信息简报
stringinfo="订单发送时间:"+ds.Tables[0].Rows[0]["sendtime"].ToString()+"曲线图生成时间:"+DateTime.Now.ToString()+"订单总量:"+Tnum.ToString()+"当前发送总量:"+nums.ToString();
g.DrawString(info,Tfont,Bluebrush,40,25);
//绘制图片边框
g.DrawRectangle(Bp,0,0,img.Width-1,img.Height-1);
//绘制竖坐标线
for(inti=0;i<count;i++)
{
g.DrawLine(Sp,40+20*i,60,40+20*i,360);
}
//绘制时间轴坐标标签
for(inti=0;i<count;i+=2)
{
stringst=Convert.ToDateTime(ds.Tables[0].Rows[i]["sendtime"]).ToString("hh:mm");
g.DrawString(st,font,brush,30+20*i,370);
}
//绘制横坐标线
for(inti=0;i<10;i++)
{
g.DrawLine(Sp,40,60+30*i,40+20*(count-1),60+30*i);
ints=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=newPoint[count];
for(inti=0;i<count;i++)
{
p[i].X=40+20*i;
p[i].Y=360-Convert.ToInt32(ds.Tables[0].Rows[i]["sendnum"])/5*3/5;
}
//绘制发送曲线
g.DrawLines(Rp,p);
for(inti=0;i<count;i++)
{
//绘制发送记录点的发送量
g.DrawString(ds.Tables[0].Rows[i]["sendnum"].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);
//保存绘制的图片
MemoryStreamstream=newMemoryStream();
img.Save(stream,ImageFormat.Jpeg);
//图片输出
page.Response.Clear();
page.Response.C;
page.Response.BinaryWrite(stream.ToArray());
}
}
相关文章
- ASP.NET_氚云开发
- ASP.NET Core 6框架揭秘实例演示[35]:利用Session保留语境
- asp.net dropdownlist的值怎么设置_ASPNET程序开发招聘
- ASP.NET中实现模板页
- 收藏的asp.net文件上传类源码
- 比较不错的asp模板引终极讲解(WEB开发之ASP模式)
- ASP.NET中高质量缩略图的生成代码
- asp.net正则表达式[经常用的到]
- asp.net购物车实现详细代码
- asp.net执行事务代码
- ASP.NET服务器路径和一般资源调用
- asp.net下用服务器端代码解决浏览器兼容性问题
- asp.net上传图片并同时生成缩略图的代码
- asp.net(c#)使用Rex正则来生成字符串数组的代码
- 鼠标右击事件代码(asp.net后台)
- ASP.NET设计网络硬盘之下载或在线查看实现代码
- asp.net中GridView和DataGrid相同列合并实现代码
- asp.net配置会话状态Session实现代码
- Asp.Net中的数据源概述与配置及实例代码
- asp.net代码中修改web.config节点的具体方法
- Asp.Net用OWC操作Excel的实例代码
- 关于ASP.NET中TreeView用法的一个小例子
- asp.net使用AJAX实现无刷新分页