using System;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page
{
DataTable mytable = db.ylTable();
protected void Page_Load(object sender, EventArgs e)
{
CreateImage();
this.GridView1.DataSource = mytable;
this.GridView1.DataBind();
}
private void CreateImage()
{
//通过数据数量计算图表宽度
int count = mytable.Rows.Count;
int width = 80 + 20 * (count - 1);
//设置最小宽度为600
if (width < 600)
width = 600;
Bitmap mybit = new Bitmap(width, 400);
Graphics mygra = Graphics.FromImage(mybit);
//定义背景
mygra.Clear(Color.WhiteSmoke);
//定义黑色画笔
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);
//定义黑色过渡型笔刷
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, mybit.Width, mybit.Height), Color.Black, Color.Black, 1.2F, true);
//定义蓝色过渡型笔刷
LinearGradientBrush Bluebrush = new LinearGradientBrush(new Rectangle(0, 0, mybit.Width, mybit.Height), Color.Blue, Color.Blue, 1.2F, true);
//绘制大标题
mygra.DrawString(mytable.Rows[0]["cgID"].ToString() + "号传感器时段压力值曲线图", Bfont, brush, 40, 5);
//绘制标题下面的概要
string smalltitle = "传感器发送时间:" +mytable.Rows[0]["sendtime"].ToString() + " 曲线图生成时间:" + DateTime.Now.ToString() ;
mygra.DrawString(smalltitle, Tfont, Bluebrush, 40, 25);
//绘制黑边框
mygra.DrawRectangle(Bp, 0, 0, mybit.Width - 1, mybit.Height - 1);
{
DataTable mytable = db.ylTable();
protected void Page_Load(object sender, EventArgs e)
{
CreateImage();
this.GridView1.DataSource = mytable;
this.GridView1.DataBind();
}
private void CreateImage()
{
//通过数据数量计算图表宽度
int count = mytable.Rows.Count;
int width = 80 + 20 * (count - 1);
//设置最小宽度为600
if (width < 600)
width = 600;
Bitmap mybit = new Bitmap(width, 400);
Graphics mygra = Graphics.FromImage(mybit);
//定义背景
mygra.Clear(Color.WhiteSmoke);
//定义黑色画笔
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);
//定义黑色过渡型笔刷
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, mybit.Width, mybit.Height), Color.Black, Color.Black, 1.2F, true);
//定义蓝色过渡型笔刷
LinearGradientBrush Bluebrush = new LinearGradientBrush(new Rectangle(0, 0, mybit.Width, mybit.Height), Color.Blue, Color.Blue, 1.2F, true);
//绘制大标题
mygra.DrawString(mytable.Rows[0]["cgID"].ToString() + "号传感器时段压力值曲线图", Bfont, brush, 40, 5);
//绘制标题下面的概要
string smalltitle = "传感器发送时间:" +mytable.Rows[0]["sendtime"].ToString() + " 曲线图生成时间:" + DateTime.Now.ToString() ;
mygra.DrawString(smalltitle, Tfont, Bluebrush, 40, 25);
//绘制黑边框
mygra.DrawRectangle(Bp, 0, 0, mybit.Width - 1, mybit.Height - 1);
//绘制竖坐标线
for (int i = 0; i < count; i++)
{
mygra.DrawLine(Sp, 40+20*i, 60, 40+20*i, 360);
}
//绘制时间轴坐标标签
for (int i = 0; i < count; i += 2)
{
string sendtime = mytable.Rows[i]["sendtime"].ToString();
mygra.DrawString(sendtime, font, brush, 30 + 20 * i, 375);
}
//绘制横坐标线
for (int i = 0; i < 10; i++)
{
mygra.DrawLine(Sp, 40, 60 + 30 * i, 40 + 20 * (count - 1), 60 + 30 * i);
int s = 2500 - 250*i;
//绘制压力值轴 数值标签
mygra.DrawString(s.ToString(), font, brush, 10, 60 + 30 * i);
}
for (int i = 0; i < count; i++)
{
mygra.DrawLine(Sp, 40+20*i, 60, 40+20*i, 360);
}
//绘制时间轴坐标标签
for (int i = 0; i < count; i += 2)
{
string sendtime = mytable.Rows[i]["sendtime"].ToString();
mygra.DrawString(sendtime, font, brush, 30 + 20 * i, 375);
}
//绘制横坐标线
for (int i = 0; i < 10; i++)
{
mygra.DrawLine(Sp, 40, 60 + 30 * i, 40 + 20 * (count - 1), 60 + 30 * i);
int s = 2500 - 250*i;
//绘制压力值轴 数值标签
mygra.DrawString(s.ToString(), font, brush, 10, 60 + 30 * i);
}
//绘制竖坐标轴
mygra.DrawLine(Bp, 40, 55, 40, 360);
//绘制横坐标轴
mygra.DrawLine(Bp, 40, 360, 45 + 20 * (count - 1), 360);
mygra.DrawLine(Bp, 40, 55, 40, 360);
//绘制横坐标轴
mygra.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(mytable.Rows[i]["sendvalue"]) / 5 * 3 / 5;
}
//绘制发送曲线
//mygra.DrawLines(Rp, p);
mygra.DrawCurve(Rp, p);
Point[] p = new Point[count];
for (int i = 0; i < count; i++)
{
p[i].X = 40 + 20 * i;
p[i].Y = 360 - Convert.ToInt32(mytable.Rows[i]["sendvalue"]) / 5 * 3 / 5;
}
//绘制发送曲线
//mygra.DrawLines(Rp, p);
mygra.DrawCurve(Rp, p);
for (int i = 0; i < count; i++)
{
//绘制发送记录点的发送量
mygra.DrawString(mytable.Rows[i]["sendvalue"].ToString(), font, Bluebrush, p[i].X, p[i].Y - 10);
//绘制发送记录点
mygra.DrawRectangle(Rp, p[i].X - 1, p[i].Y - 1, 2, 2);
}
//绘制竖坐标标题
mygra.DrawString("压力值坐标轴", Tfont, brush, 5, 40);
//绘制横坐标标题
mygra.DrawString("发送时间坐标轴", Tfont, brush, mybit.Width-100, 385);
{
//绘制发送记录点的发送量
mygra.DrawString(mytable.Rows[i]["sendvalue"].ToString(), font, Bluebrush, p[i].X, p[i].Y - 10);
//绘制发送记录点
mygra.DrawRectangle(Rp, p[i].X - 1, p[i].Y - 1, 2, 2);
}
//绘制竖坐标标题
mygra.DrawString("压力值坐标轴", Tfont, brush, 5, 40);
//绘制横坐标标题
mygra.DrawString("发送时间坐标轴", Tfont, brush, mybit.Width-100, 385);
//输出保存
mybit.Save(Server.MapPath("") + @"/qq.png", ImageFormat.Png);
//mybit.Save(Response.OutputStream, ImageFormat.Jpeg);
mygra.Dispose();
mybit.Dispose();
}
}
mybit.Save(Server.MapPath("") + @"/qq.png", ImageFormat.Png);
//mybit.Save(Response.OutputStream, ImageFormat.Jpeg);
mygra.Dispose();
mybit.Dispose();
}
}
create database ylcg
create table yl
(
ylID int identity(1,1) primary key,
sendtime varchar(20),
sendvalue int,
cgID int not null
)
create table yl
(
ylID int identity(1,1) primary key,
sendtime varchar(20),
sendvalue int,
cgID int not null
)