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

Reading number is top 10 articles
剖析SQL Server2005 SQLCLR代码安全性_[SQL Server教程]
ASP.Net2.0,GridView,多列排序,显示排序图标,分页_[Asp.Net教程]
asp.net,2.0中不同web控件之间的相互调用_.net资料_编程技术
C#视频教程_[Asp.Net教程]
C#中TextBox控件应用实例
ASP.NET应用程序安全性问题_[Asp.Net教程]
HTML 初学者指南(7)_[Html教程]
HTML语言剖析(十)链接标记_[Html教程]
PHP开发实例:创建PDF中文文档的程序代码_php资料_编程技术
PHP新手总结的PHP基础知识_php资料_编程技术
Reading number is top 10 pictures
XuRe xuan cool and refreshing photoes1
陪睡门马睿菈自曝写真 称首拍大尺度照片3
So beauty, will let you spray blood10
这才是真正的人体艺术2
Forced sex girl living abroad1
移民小国也实惠2
A man's favorite things4
Female model behind the bitterness, often being overcharged2
China's first snake village1
Extremely rare TianShan Mountains snow lotus2
Download software ranking
电脑知识及技巧大合集
Tram sex maniac 2 (H) rar bag2
株洲本地在线棋牌游戏
Tram sex maniac 2 (H) rar bag11
Boxer's Top ten classic battle6
Tram sex maniac 2 (H) rar bag7
Boxer's Top ten classic battle3
Boxer's Top ten classic battle10
功夫熊猫2(下集)
I'm come from Beijing1
qq published in(发表于) 2014/7/11 9:29:08 Edit(编辑)
GDI+ 绘制折线图分析网站流量

GDI+ 绘制折线图分析网站流量

GDI+ 绘制折线图分析网站流量

绘制折线图分析网站流量

折线图是网站开发中经常用到的一种图表技术,折线图可以很直观地反映出相关数据的变化趋势。本节通过一个实例来介绍如何使用折线图分析网站的流量。实例运行结果如图1所示。

程序开发步骤如下所示。

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

(2)在该网站中添加一个Info.aspx页面,该页面主要用来使用折线图显示各月份的网站访问人数。

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



图1 折线图分析网站流量

Info.aspx页面中定义了一个方法CreateImage,该方法主要用来从数据库中提取数据,并根据提取的数据,调用Graphics对象的相关方法绘制一张反映网站流量情况的折线图。CreateImage方法实现代码如下:

private void CreateImage(int P_int_year)

{

int height = 400, width = 600;

Bitmap image = new Bitmap(width, height);

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);

string P_str_sum = "SELECT * FROM tb_03 WHERE yearID=" + P_int_year + "";

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

sqlcon.Open();

SqlCommand sqlcom = new SqlCommand(P_str_sum, sqlcon);

SqlDataReader sqlread = sqlcom.ExecuteReader(CommandBehavior.CloseConnection);

sqlread.Read();

if (sqlread.HasRows)

{

graphics.DrawString("" + P_int_year + "年各月份网站访问人数", font1, brush1, new PointF(130, 30));

}

sqlread.Close();

//画图片的边框线

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, 340);

x = x + 40;

}

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

Pen mypen2 = new Pen(Color.Red, 2);

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

//绘制纵向线条

int y = 106;

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

{

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

y = y + 26;

}

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

//x轴

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

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

x = 35;

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

{

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

x = x + 40;

}

//y轴

String[] m = { " 900人", " 800人", " 700人", " 600人", " 500人", " 400人", " 300人",

" 200人", " 100人", " 0人"};

y = 98;

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

{

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

y = y + 26;

}

int[] Count = new int[12];

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

SqlDataAdapter myda = new SqlDataAdapter(P_str_yearID, sqlcon);

DataSet myds = new DataSet();

myda.Fill(myds);

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

{

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

}

SolidBrush mybrush = new SolidBrush(Color.Red);

Point[] myPoint = new Point[12];

myPoint[0].X = 60; myPoint[0].Y = 340 - Count[0];

myPoint[1].X = 100; myPoint[1].Y = 340 - Count[1];

myPoint[2].X = 140; myPoint[2].Y = 340 - Count[2];

myPoint[3].X = 180; myPoint[3].Y = 340 - Count[3];

myPoint[4].X = 220; myPoint[4].Y = 340 - Count[4];

myPoint[5].X = 260; myPoint[5].Y = 340 - Count[5];

myPoint[6].X = 300; myPoint[6].Y = 340 - Count[6];

myPoint[7].X = 340; myPoint[7].Y = 340 - Count[7];

myPoint[8].X = 380; myPoint[8].Y = 340 - Count[8];



添加到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.