protected void Page_Load(object sender, EventArgs e)
{
DB db = new DB();
string id = Application["id1"].ToString();
Label15.Text = id;
TextBox8.Text = id;
string sqlStr1 = "select 限额 from 普通用户信息表 where 账号=" + id;
TextBox1.Text = db.reDt(sqlStr1).Rows[0]["限额"].ToString();
string sqlStr2 = "select 密码 from 普通用户信息表 where 账号=" + id;
TextBox3.Text = db.reDt(sqlStr2).Rows[0]["密码"].ToString();
string sqlStr3 = "select 余额 from 普通用户信息表 where 账号=" + id;
TextBox9.Text = db.reDt(sqlStr3).Rows[0]["余额"].ToString();
string sqlStr4 = "select 补助金额 from 补助领取信息表 where 账号=" + id;
TextBox7.Text = db.reDt(sqlStr4).Rows[0]["补助金额"].ToString();
string sqlStr5 = "select 余额 from 普通用户信息表 where 账号=" + id;
TextBox12.Text = db.reDt(sqlStr5).Rows[0]["余额"].ToString();
Panel15.Visible = false;
Panel16.Visible = false;
DB db = new DB();
string cmdtxt = "select * from 消费信息表 where 账号='131909030115'";
DataTable dt = db.reDt(cmdtxt);
float Total = 0.0f, Tmp;
for (int i = 0; i < dt.Rows.Count; i++)
{
//转换成单精度,也可写成Convert.ToInt32
Tmp = Convert.ToSingle(dt.Rows[i]["消费金额"]);
Total += Tmp;
}
//设置字体,fonttitle为主标题的字体
Font fontlegend = new Font("verdana", 9);
Font fonttitle = new Font("verdana", 10, FontStyle.Bold);
//背景宽
int width = 230;
int bufferspace = 15;
int legendheight = fontlegend.Height * (dt.Rows.Count + 1) + bufferspace;
int titleheight = fonttitle.Height + bufferspace;
int height = width + legendheight + titleheight + bufferspace;//白色背景高
int pieheight = width;
Rectangle pierect = new Rectangle(0, titleheight, width, pieheight);
//加上各种随机色
ArrayList colors = new ArrayList();
Random rnd = new Random();
for (int i = 0; i < dt.Rows.Count; i++)
colors.Add(new SolidBrush(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255))));
//创建一个bitmap实例
Bitmap objbitmap = new Bitmap(width, height);
Graphics objgraphics = Graphics.FromImage(objbitmap);
//画一个白色背景
objgraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height);
//画一个亮黄色背景
objgraphics.FillRectangle(new SolidBrush(Color.Beige), pierect);
//以下为画饼图(有几行row画几个)
float currentdegree = 0.0f;
float[] Tot = { 0.0f, 0.0f, 0.0f };
float Tmp1, Tmp2, Tmp3;
for (int i = 0; i < dt.Rows.Count; i++)
{
if ((String)dt.Rows[i]["消费类型"] == "饮食")
{
//转换成单精度,也可写成Convert.ToInt32
Tmp1 = Convert.ToSingle(dt.Rows[i]["消费金额"]);
Tot[0] += Tmp1;
}
if ((String)dt.Rows[i]["消费类型"] == "学习")
{
//转换成单精度,也可写成Convert.ToInt32
Tmp2 = Convert.ToSingle(dt.Rows[i]["消费金额"]);
Tot[1] += Tmp2;
}
if ((String)dt.Rows[i]["消费类型"] == "生活")
{
//转换成单精度,也可写成Convert.ToInt32
Tmp3 = Convert.ToSingle(dt.Rows[i]["消费金额"]);
Tot[2] += Tmp3;
}
}
for (int i = 0; i < 3; i++)
{
objgraphics.FillPie((SolidBrush)colors[i], pierect, currentdegree, Convert.ToSingle(Tot[i]) / Total * 360);
currentdegree += Convert.ToSingle(Tot[i]) / Total * 360;
}
//以下为生成主标题
SolidBrush blackbrush = new SolidBrush(Color.Black);
string title = "各种消费类型所占比例";
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
objgraphics.DrawString(title, fonttitle, blackbrush, new Rectangle(0, 0, width, titleheight), stringFormat);
//列出各字段及所占百分比
objgraphics.DrawRectangle(new Pen(Color.Black, 2), 0, height - legendheight, width, legendheight);
for (int i = 0; i < 3; i++)
{
if (i == 0)
{
objgraphics.FillRectangle((SolidBrush)colors[i], 5, height - legendheight + fontlegend.Height * i + 5, 10, 10);
objgraphics.DrawString(("饮食") + "——" + Convert.ToString(Convert.ToSingle(Tot[i]) * 100 / Total).Substring(0, 2) + "%", fontlegend, blackbrush, 20, height - legendheight + fontlegend.Height * i + 1);
}
if (i == 1)
{
objgraphics.FillRectangle((SolidBrush)colors[i], 5, height - legendheight + fontlegend.Height * i + 5, 10, 10);
objgraphics.DrawString(("学习") + "——" + Convert.ToString(Convert.ToSingle(Tot[i]) * 100 / Total).Substring(0, 2) + "%", fontlegend, blackbrush, 20, height - legendheight + fontlegend.Height * i + 1);
}
if (i == 2)
{
objgraphics.FillRectangle((SolidBrush)colors[i], 5, height - legendheight + fontlegend.Height * i + 5, 10, 10);
objgraphics.DrawString(("生活") + "——" + Convert.ToString(Convert.ToSingle(Tot[i]) * 100 / Total).Substring(0, 2) + "%", fontlegend, blackbrush, 20, height - legendheight + fontlegend.Height * i + 1);
}
}
//图像总的高度——一行字体的高度,即是最底行的一行字体高度(height-fontlegend.Height)
objgraphics.DrawString("消费总数:" + Convert.ToString(Total) + "元", fontlegend, blackbrush, 5, height - fontlegend.Height);
Response.ContentType = "image/Jpeg";
objbitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
objgraphics.Dispose();
objbitmap.Dispose();
}
你这个页面输出动态图片而已,用img标签加载就行了,panel对应客户端的div,无法加载图片。你要放panel里面下面的html放panel里面就行了
<img src="你这个aspx页面的url地址"/>