All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
用sql存储过程实现前台标题变色_[SQL Server教程]
大型系统上PHP令人不爽的九大原因_php资料_编程技术
优化mysql性能的十个参数的详细介绍_php资料_编程技术
ASP.NET2.0的新增服务、控件与功能_[Asp.Net教程]
用,PHP,V5,开发多任务应用程序_php资料_编程技术
C#教程:注册COM+服务组件应用实例
编写高性能,Web,应用程序的10个技巧_[Asp.Net教程]
Sql,Server2005实现远程备份数据库_mssql学习_编程技术
ASP.NET(C#)生成静态html页面_[Asp.Net教程]
单击gridview中记录在右下方显示详细信息_[Asp.Net教程]
Reading number is top 10 pictures
More attractive than sora aoi3
Take you to walk into the most true north Korea rural3
这才是真正的人体艺术5
The little girl with long hair3
Most cow mistress ZhaoGongXia face exposure
Absolutely shocked. National geographic 50 animal photographys3
NeedWallpaper2
30 beautiful school beauty1
你白吃了多少药
NeedWallpaper9
Download software ranking
传奇私服架设教程-chm
中国结婚习俗实录
Proficient in Eclipse
终极变速大师Speeder3.26
Unix video tutorial12
linux高级编程
VC++6.0简体中文版
在线棋牌游戏3.05版
Tram sex maniac 2 (H) rar bag3
Detective task-the top secret prostitution files
qq published in(发表于) 2014/7/11 9:29:14 Edit(编辑)
GDI+绘制柱型图分析商品月销售情况

GDI+绘制柱型图分析商品月销售情况

GDI+绘制柱型图分析商品月销售情况

绘制柱型图分析商品月销售情况

柱型图也称为条形图,它是网站开发中最常用的一种图表技术之一。本节通过一个实例来介绍使用柱型图分析商品的月销售情况。实例运行结果如图1所示。



程序开发步骤如下所示。

(1)新建一个网站,命名为26_01,其主页默认为Default.aspx。

(2)在该网站中添加一个Info.aspx页面,该页面主要用来使用柱型图显示各月份的商品销售情况。

(3)程序主要代码如下。

Info.aspx页面中定义了两个方法,分别为sumNum方法和CreateImage方法,其中sumNum方法用来计算各月份的商品销售量总和,而CreateImage方法则用来调用Graphics对象的相关方法绘制柱型图。sumNum方法实现代码如下:

private int sumNum(int P_int_year)

{

string P_str_sum = "SELECT SUM(month1+month2+month3+month4+month5+month6+month7+month8+month9+ month10+month11+month12) AS number FROM tb_01 WHERE yearID=" + P_int_year + "";

SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["connectionString"]);

SqlDataAdapter myda = new SqlDataAdapter(P_str_sum, sqlcon);

DataSet myds = new DataSet();

myda.Fill(myds);

return Convert.ToInt32(myds.Tables[0].Rows[0][0].ToString());

}

CreateImage方法实现代码如下:

private void CreateImage(int P_int_year)

{

int height = 400, width = 600;

Bitmap image = new Bitmap(width, height);

//创建Graphics类对象

Graphics graphics = Graphics.FromImage(image);

try

{

//清空图片背景色

graphics.Clear(Color.White);

Font font = new Font("Arial", 9, FontStyle.Regular);

Font font1 = new Font("宋体", 20, FontStyle.Regular);

LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.Blue, 1.2f, True);

graphics.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);

Brush brush1 = new SolidBrush(Color.Blue);

graphics.DrawString("" + P_int_year + "年商品月销售情况", font1, brush1, new PointF(150, 30));

//画图片的边框线

graphics.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++)

{

graphics.DrawLine(mypen, x, 80, x, 366);

x = x + 40;

}

Pen mypen1 = new Pen(Color.Blue, 2);

graphics.DrawLine(mypen1, x - 480, 80, x - 480, 366);

//绘制纵向线条

int y = 106;

for (int i = 0; i < 10; i++)

{

graphics.DrawLine(mypen, 60, y, 540, y);

y = y + 26;

}

graphics.DrawLine(mypen1, 60, y, 540, y);

//x轴

String[] n = {" 一月", " 二月", " 三月", " 四月", " 五月", " 六月", " 七月",

" 八月", " 九月", " 十月", "十一月", "十二月"};

x = 60;

for (int i = 0; i < 12; i++)

{

graphics.DrawString(n[i].ToString(), font, Brushes.Red, x, 374); //设置文字内容及输出位置

x = x + 40;

}

//y轴

String[] m = {"100%", " 90%", " 80%", " 70%", " 60%", " 50%", " 40%", " 30%",

" 20%", " 10%", " 0%"};

y = 98;

for (int i = 0; i < 11; i++)

{

graphics.DrawString(m[i].ToString(), font, Brushes.Red, 25,y); //设置文字内容及输出位置

y = y + 26;

}

int[] Count = new int[12];

string P_str_yearID = "SELECT * FROM tb_01 WHERE yearID=" + P_int_year + "";

SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["connectionString"]);

SqlDataAdapter myda = new SqlDataAdapter(P_str_yearID, sqlcon);

DataSet myds = new DataSet();

myda.Fill(myds);

int P_int_num = sumNum(P_int_year);

for (int j = 0; j < 12; j++)

{

Count[j] = Convert.ToInt32(myds.Tables[0].Rows[0][j + 1].ToString()) * 100 / P_int_num;

}

//显示柱状效果

x = 70;

for (int i = 0; i < 12; i++)

{

SolidBrush mybrush = new SolidBrush(Color.Red);

graphics.FillRectangle(mybrush, x, 366 - Count[i] * 26 / 10, 20, Count[i] * 26 / 10);

x = x + 40;

}

System.IO.MemoryStream MStream = new System.IO.MemoryStream();

image.Save(MStream, System.Drawing.Imaging.ImageFormat.Gif);

Response.ClearContent();

Response.ContentType = "image/Gif";

Response.BinaryWrite(MStream.ToArray());

}

finally



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.