📄 default2.aspx.cs
字号:
using System;
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.Drawing;
using System.Drawing.Imaging;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DrawClairvoyantPic();
}
//绘制透视图
protected void DrawClairvoyantPic()
{
int height = 380;
int x = 73;
for (int i = 0; i < Session.Count / 2; i++)
{
x = x + 40;
}
System.Drawing.Bitmap image = new System.Drawing.Bitmap(x + 150, height);
//创建Graphics类对象
Graphics g = Graphics.FromImage(image);
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, x + 150, height);
Brush brush1 = new SolidBrush(Color.Blue);
//画图片的边框线
g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);
Pen mypen = new Pen(brush, 1);
//绘制线条
//绘制横向线条
x = 100;
for (int i = 0; i < Session.Count / 2 - 1; i++)
{
g.DrawLine(mypen, x, 80, x, 340);
x = x + 40;
}
Pen mypen1 = new Pen(Color.Blue, 2);
g.DrawLine(mypen1, 60, 80, 60, 340);
g.DrawString("员工薪水透视图", font1, brush1, new PointF((x - 100) / 2, 30));
//绘制纵向线条
int y = 106;
for (int i = 0; i < 9; i++)
{
g.DrawLine(mypen, 60, y, x + 20, y);
y = y + 26;
}
g.DrawLine(mypen1, 60, y, x + 20, y);
//x轴
x = 73;
for (int i = 0; i < Session.Count / 2; i++)
{
g.DrawString(Session["name" + i].ToString(), font, Brushes.Red, x, 348); //设置文字内容及输出位置
x = x + 40;
}
String[] m = {"7200", "6400", "5600", "4800", "4000", "3200", "2400", "1600",
"800"};
y = 100;
for (int i = 0; i < 9; i++)
{
g.DrawString(m[i].ToString(), font, Brushes.Red, 20, y); //设置文字内容及输出位置
y = y + 26;
}
int[] Count = new int[Session.Count / 2];
for (int j = 0; j < Session.Count / 2; j++)
{
Count[j] = Convert.ToInt32(Session["salary" + j].ToString());
}
//加上各种随机色
ArrayList colors = new ArrayList();
Random rnd = new Random();
for (int i = 0; i < Session.Count / 2; i++)
colors.Add(new SolidBrush(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255))));
//显示透视效果
x = 70;
for (int i = 0; i < Session.Count / 2; i++)
{
g.FillRectangle((SolidBrush)colors[i], x, 340 - Count[i] * 26 / 800, 20, Count[i] * 26 / 800);
x = x + 40;
}
//列出各字段及数目
g.DrawRectangle(new Pen(Color.Black, 1), x + 30, 80, 115, 10 * (Session.Count / 2) + 18);
for (int i = 0; i < Session.Count / 2; i++)
{
g.FillRectangle((SolidBrush)colors[i], x + 40, 10 * i + 90, 20, 10);
g.DrawString(Session["name" + i].ToString() + " —— " + Count[i], new Font("verdana", 9), new SolidBrush(Color.Black),
x + 60, 10 * i + 87);
}
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
g.Dispose();
image.Dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -