.NET 页面中用代码画图用来表示百分比例[WEB学习示例]
2008-10-19 10:51
393 查看
protected void Page_Load(object sender, EventArgs e)
{
int height = 600, width = 600;
System.Drawing.Bitmap image = new System.Drawing.Bitmap(height, width);
Graphics g = Graphics.FromImage(image);
g.Clear(Color.Wheat);
Font font = new System.Drawing.Font("Arial", 9, FontStyle.Regular);
Font font1 = new System.Drawing.Font("隶书", 20, FontStyle.Regular);
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.Blue, 1.2f, true);
g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);
Brush brush1 = new SolidBrush(Color.Blue);
g.DrawString("" + "统计统计统计统计统计", font1, brush1, new PointF(100, 30));
g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);
Pen mypen = new Pen(brush, 1);
int x = 100;
for (int i = 0; i < 11; i++)
{ g.DrawLine(mypen, x, 80, x, 340); x = x + 40; }
Pen mypen1 = new Pen(Color.Blue, 2);
g.DrawLine(mypen1, x - 480, 80, x - 480, 340);
int y = 106;
for (int i = 0; i < 9; i++)
{ g.DrawLine(mypen, 60, y, 540, y); y = y + 26; }
g.DrawLine(mypen1, 60, y, 540, y);
string[] n = { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" };
x = 62;
for (int i = 0; i < 12; i++)
{ g.DrawString(n[i].ToString(), font, Brushes.Red, x, 348); x = x + 40; }
string[] m = { "100%", "90%", "80%", "70%", "60%", "50%", "40%", "30%", "20%", "10%", "0%" };
y = 85;
for (int i = 0; i < 11; i++)
{ g.DrawString(m[i].ToString(), font, Brushes.Red, 25, y); y = y + 26; }
//
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.BinaryWrite(ms.ToArray());
}
{
int height = 600, width = 600;
System.Drawing.Bitmap image = new System.Drawing.Bitmap(height, width);
Graphics g = Graphics.FromImage(image);
g.Clear(Color.Wheat);
Font font = new System.Drawing.Font("Arial", 9, FontStyle.Regular);
Font font1 = new System.Drawing.Font("隶书", 20, FontStyle.Regular);
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.Blue, 1.2f, true);
g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);
Brush brush1 = new SolidBrush(Color.Blue);
g.DrawString("" + "统计统计统计统计统计", font1, brush1, new PointF(100, 30));
g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);
Pen mypen = new Pen(brush, 1);
int x = 100;
for (int i = 0; i < 11; i++)
{ g.DrawLine(mypen, x, 80, x, 340); x = x + 40; }
Pen mypen1 = new Pen(Color.Blue, 2);
g.DrawLine(mypen1, x - 480, 80, x - 480, 340);
int y = 106;
for (int i = 0; i < 9; i++)
{ g.DrawLine(mypen, 60, y, 540, y); y = y + 26; }
g.DrawLine(mypen1, 60, y, 540, y);
string[] n = { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" };
x = 62;
for (int i = 0; i < 12; i++)
{ g.DrawString(n[i].ToString(), font, Brushes.Red, x, 348); x = x + 40; }
string[] m = { "100%", "90%", "80%", "70%", "60%", "50%", "40%", "30%", "20%", "10%", "0%" };
y = 85;
for (int i = 0; i < 11; i++)
{ g.DrawString(m[i].ToString(), font, Brushes.Red, 25, y); y = y + 26; }
//
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.BinaryWrite(ms.ToArray());
}
相关文章推荐
- Asp.net 2.0 自定义控件开发[开发一个图表(WebChart)控件(柱状图示例)](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- MSDN官方的ASP.Net异步页面的经典示例代码
- Asp.net 2.0 自定义控件开发[开发一个图表(WebChart)控件(柱状图示例)](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- Asp.net 2.0 自定义控件开发[开发一个图表(WebChart)控件(柱状图示例)](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- Asp.net 2.0 自定义控件开发[开发一个图表(WebChart)控件(柱状图示例)](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- 一步步学习SPD2010--第十四章节--在Web页面使用控件(6)--测试ASP.NET表单
- Asp.net中判断是否是指定页面请求的代码示例
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- Asp.net 2.0 自定义控件开发[开发一个图表(WebChart)控件(柱状图示例)](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- Microsoft .NET 的企业解决方案模式 > Web 表示模式 > 模型-视图-控制器(学习笔记四)
- 一步步学习SPD2010--第十四章节--在Web页面使用控件(4)--使用ASP.NET验证控件
- ASP.NET学习5--N层代码示例
- Asp.net 2.0 自定义控件开发[开发一个图表(WebChart)控件(柱状图示例)](示例代码下载)