asp.net画个简单的折线图,显示不出来?(C#)
usingSystem;usingSystem.Collections.Generic;usingSystem.Web;usingSystem.Web.UI;usingS...
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.pic();
}
protected void pic()
{
float[] shuzu = new float[] { 0f, 0.6328f, 1f };
float[] shuzu2 = new float[] { 0f, 0, 4923f, 1f };
int m = shuzu.Length;
int[] shuzuint = new int[m];
int[] shuzuint2 = new int[m];
for (int i = 0; i < m; i++)
{
shuzuint[i] = (int)(shuzu[i]*300);
shuzuint2[i] = (int)(shuzu2[i] * 300);
}
Bitmap img = new Bitmap(400, 400);
//生成绘图对像
Graphics g = Graphics.FromImage(img);
g.Clear(Color.White);
Pen Blp = new Pen(Color.Blue);
Pen Bp = new Pen(Color.Black);
Pen Rp = new Pen(Color.Red);
Pen Sp = new Pen(Color.Silver);
g.DrawRectangle(Bp, 0, 0, img.Width - 1, img.Height - 1);
g.DrawLine(Bp, 10, 10, 10, 310);
g.DrawLine(Bp, 10, 310, 310, 310);
Point[] p = new Point[m];
for (int i = 0; i < m; i++)
{
p[i].X = 10+shuzuint[i];
p[i].Y = 310-shuzuint2[i];
}
g.DrawLines(Blp, p);
}
在浏览器中查看,什么都没有显示出来,求教这是为什么呢? 展开
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.pic();
}
protected void pic()
{
float[] shuzu = new float[] { 0f, 0.6328f, 1f };
float[] shuzu2 = new float[] { 0f, 0, 4923f, 1f };
int m = shuzu.Length;
int[] shuzuint = new int[m];
int[] shuzuint2 = new int[m];
for (int i = 0; i < m; i++)
{
shuzuint[i] = (int)(shuzu[i]*300);
shuzuint2[i] = (int)(shuzu2[i] * 300);
}
Bitmap img = new Bitmap(400, 400);
//生成绘图对像
Graphics g = Graphics.FromImage(img);
g.Clear(Color.White);
Pen Blp = new Pen(Color.Blue);
Pen Bp = new Pen(Color.Black);
Pen Rp = new Pen(Color.Red);
Pen Sp = new Pen(Color.Silver);
g.DrawRectangle(Bp, 0, 0, img.Width - 1, img.Height - 1);
g.DrawLine(Bp, 10, 10, 10, 310);
g.DrawLine(Bp, 10, 310, 310, 310);
Point[] p = new Point[m];
for (int i = 0; i < m; i++)
{
p[i].X = 10+shuzuint[i];
p[i].Y = 310-shuzuint2[i];
}
g.DrawLines(Blp, p);
}
在浏览器中查看,什么都没有显示出来,求教这是为什么呢? 展开
2个回答
2011-03-04
展开全部
不能这样直接用哈。
首先,你需要在你的pic方法添加如下输出图片的代码:
Response.Clear();
img.Save(Response.OutputStream, ImageFormat.Gif);
Response.ContentType = "img/gif";
Response.Flush();
Response.End();
其次,你需要把这个页面的地址赋给img控件的src属性,如下,你可以新建一个页面:
...
<img src="WebForm1.aspx" /><!--假定WebForm1.aspx就是输出图片的页面-->
...
首先,你需要在你的pic方法添加如下输出图片的代码:
Response.Clear();
img.Save(Response.OutputStream, ImageFormat.Gif);
Response.ContentType = "img/gif";
Response.Flush();
Response.End();
其次,你需要把这个页面的地址赋给img控件的src属性,如下,你可以新建一个页面:
...
<img src="WebForm1.aspx" /><!--假定WebForm1.aspx就是输出图片的页面-->
...
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询