折线统计图(转载)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了折线统计图(转载),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3390字,纯文字阅读大概需要5分钟。
内容图文
![折线统计图(转载)](/upload/InfoBanner/zyjiaocheng/1325/714e630be5c24f83af031d1c336e1fae.jpg)
using System;
using System.Collections.Generic;
using
System.Linq;
using System.Web;
using System.Web.UI;
using
System.Web.UI.WebControls;
using System.Data.SqlClient;
using
System.Configuration;
using System.Drawing;
using System.IO;
using
System.Drawing.Drawing2D;
using System.Data;
public partial class LineTJImage : System.Web.UI.Page
{
public
string connStr =
ConfigurationManager.ConnectionStrings["VisitCountConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
DrawLinearGradient();
}
//访问人数统计
public int Total()
{
int result = -1;
string sql = "select count(1) from
VisiteCount";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
result = Convert.ToInt32(cmd.ExecuteScalar());
cmd.Dispose();
conn.Close();
return result;
}
//柱形图
public
void DrawLinearGradient()
{
int width = 600, height = 400;
Bitmap image = new Bitmap(width,height);
Graphics g =
Graphics.FromImage(image);
g.Clear(Color.White);
//画矩形
g.FillRectangle(Brushes.WhiteSmoke, new Rectangle(0, 0, width,
height));
LinearGradientBrush brush = new LinearGradientBrush(new
Rectangle(0,0,width,height),Color.Blue,Color.BlueViolet,1.2f,true);
Font font = new Font("Arial",9,FontStyle.Regular);
Font font1 = new
Font("宋体",20,FontStyle.Bold);
//写标题
g.DrawString("2013网站浏览次数统计",font1,brush,new PointF(120,30));
Pen pen = new Pen(Color.Blue);
Pen pen1 = new Pen(Color.Blue,2);
//画边框
g.DrawRectangle(pen, 0, 0, width-1, height - 1);
//设定横向起始
int x = 100;
for (int i = 0; i < 11; i++)
{
g.DrawLine(pen, x, 80, x, 340);
x += 40;
}
//画y轴线
int y = 106;
for (int i = 0; i <9;
i++)
{
g.DrawLine(pen, 60, y,540,y);
y
+= 26;
}
g.DrawLine(pen1, 60, y, 540, y);
//画X轴线条
g.DrawLine(pen1,x-480,80,x-480,340);
//X轴
string[] n =
{"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
x = 62;
for (int i = 0; i < 12; i++)
{
g.DrawString(n[i],font,Brushes.Black,new PointF(x,348));
x +=
40;
}
g.DrawString("人/月", new
Font("宋体",10,FontStyle.Italic), Brushes.Black, new PointF(35, 348));
//y轴
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.Black, 25,
y);//设置文字内容以及输出位置
y = y + 25;
}
//将检索出的数据按一定比例绘制到图像中
int[] count = new int[12];
string sql =
"";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlDataAdapter da;
DataSet ds = new
DataSet();
for (int i = 0; i < 12; i++)
{
sql = @"select count(1) as count,Month(loginTime) as month from VisiteCount
where YEAR(loginTime)=2013 and MONTH(loginTime)=" + (i + 1) + " group by
MONTH(loginTime)";
da = new SqlDataAdapter(sql, conn);
da.Fill(ds, i.ToString());
if (ds.Tables[i].Rows.Count ==
0)
{
count[i] = 0;
}
else
{
//count[i] =
Convert.ToInt32(ds.Tables[i].Rows[0][0].ToString())*100/Total();
count[i] = Convert.ToInt32(ds.Tables[i].Rows[0][0].ToString());
}
}
x = 70;
Point[] points = new
Point[12];
for (int i = 0; i < 12; i++)
{
//g.DrawLine(pen
//g.DrawLine(pen, x, 340 - count[i] * 26 / 10,
20, count[i] * 26 / 10);
points[i] = new Point(x, 340 - count[i]
* 26 / 10);
x += 40;
}
g.DrawLines(pen,points);
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "image/Jpeg";
Response.BinaryWrite(ms.ToArray());
}
}
原文:http://www.cnblogs.com/chengzitingBlog/p/3533860.html
内容总结
以上是互联网集市为您收集整理的折线统计图(转载)全部内容,希望文章能够帮你解决折线统计图(转载)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。