提供了数据表,请高手帮忙设计个.NET的曲线图(在线等一晚上,急)
数据表:记录交换机端口状态和状态转换的时间字段名(类型) 意义
Ip(char) IP
Port(char) 端口
Status(char) 状态(up down)
LoginTime(datetime) 上机时间
LogoffTime(datetime) 下机时间
部分记录:
10.10.143.2:56829 10.10.143.2:5682 Active 2008-4-21 19:43:32 2008-4-20 23:08:05
10.10.143.3:56598 10.10.143.3:5659 Active 2008-4-21 22:36:24 2008-4-21 18:10:26
10.10.192.2:51548 10.10.192.2:5154 Down 2008-4-21 20:12:24 2008-4-21 22:28:41
统计某时间的在线人数
例如:你要统计2008-4-14 2:00:00的在线数量,你的SQL语句为:
select count( port ) from active
where ( logintime <= '2008-4-14 2:00:00' and logofftime >= '2008-4-14 2:00:00' )
or
( logintime <= '2008-4-14 2:00:00' and status = 'active' );
想从上面的表中.生成一个曲线图..
平台:NET 2005 语言:C#
曲线图每隔5或10分钟统计一次当前在线人数.
你可以就使用上面的表作为数据源.也可以另建表
请高手帮忙下...送80分...
或者加我QQ:119554917
解决了,必有答谢,送礼物,很急呀,在线等一晚上.谢谢谢谢~~~~ --------------------编程问答-------------------- 焦急等待中~~~ --------------------编程问答-------------------- 我前几天刚写的曲线图,有点简陋,你看看能不能用.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
public partial class Curve : System.Web.UI.UserControl
{
int _Width, _Height;
protected void Page_Load(object sender, EventArgs e)
{
DrawMap image = new DrawMap(_Width, _Height);
//Random Rad = new Random();
//string text = Rad.Next(1000, 9999).ToString();
//Session["Code"] = text;
//这里放各个点,东西现在是死的,各个节点是固定的,不过你可以自己做小小修改
//不过曲节图网上控件很多的,你可以从网上自己下下来
byte[] ImageBuffer = image.getBitmap(new decimal[] { 20,10,40,30,88,50,80,70,90,23.4M,13.4M,54,46,65.7M,34.5M,24.3M,24.3M,65 });
MemoryStream ms = new MemoryStream(ImageBuffer);
Bitmap bitmap = new Bitmap(ms);
bitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
}
public class DrawMap
{
int _Width, _Height;
public DrawMap(int Width, int Height)
{
this._Width = Width;
this._Height = Height;
}
private Bitmap bitmap;
//图型对象
private Graphics gp;
//使用字体
private Font drawFont;
//内存存储空间(图型)
private MemoryStream ms;
public byte[] getBitmap(decimal[] Datas)
{
byte[] arrImage;
bitmap = new Bitmap(_Width, _Height);
gp = Graphics.FromImage(bitmap);
drawFont = new Font("Arial", 12, FontStyle.Bold);
gp.Clear(Color.FromArgb(249, 247, 221));
int margin_X = 15;
int margin_Y = 40;
Color lineColor = Color.FromArgb(134, 134, 134);
Point[] linesPoint = new Point[Datas.Length];
decimal max, min;
max = Datas.Max();
min = Datas.Min();
//画X轴
gp.DrawLine(new Pen(lineColor), margin_Y - 3, this._Height - margin_Y, this._Width - margin_X, this._Height - margin_Y);
gp.DrawLine(new Pen(lineColor), this._Width - margin_X - 6, this._Height - margin_Y - 6, this._Width - margin_X, this._Height - margin_Y);
gp.DrawLine(new Pen(lineColor), this._Width - margin_X - 6, this._Height - margin_Y + 6, this._Width - margin_X, this._Height - margin_Y);
//画Y轴
gp.DrawLine(new Pen(lineColor), margin_Y, margin_X, margin_Y, this._Height - margin_Y);
gp.DrawLine(new Pen(lineColor), margin_Y, margin_X, margin_Y + 6, margin_X + 6);
gp.DrawLine(new Pen(lineColor), margin_Y, margin_X, margin_Y - 6, margin_X + 6);
decimal csale = (_Height - margin_Y - margin_X) / (max - min);
for (int i = 0; i < Datas.Length; i++)
{
linesPoint[i] = new Point((_Width - margin_X - margin_Y) / Datas.Length * i + margin_Y,
_Height - Convert.ToInt32((Datas[i] - min) * csale) -margin_Y);
//点标记
gp.DrawString(Datas[i].ToString(), new Font("宋体", 10F), Brushes.Purple, linesPoint[i].X + 5, linesPoint[i].Y - 10);
//Y轴刻度
gp.DrawLine(new Pen(lineColor),
(_Width - margin_X - margin_Y) / Datas.Length * i + margin_Y,
this._Height - margin_Y,
(_Width - margin_X - margin_Y) / Datas.Length * i + margin_Y,
this._Height - margin_Y + 3);
gp.DrawString(i.ToString(), new Font("宋体", 10F), Brushes.Purple, linesPoint[i].X - 5, this._Height - margin_Y + 3);
}
StringFormat kedu = new StringFormat(StringFormatFlags.DirectionRightToLeft);
//写Y轴刻度
gp.DrawString(min.ToString(), new Font("宋体", 10F), Brushes.BlueViolet, 37, this._Height - margin_Y - 5, kedu);
gp.DrawString(max.ToString(), new Font("宋体", 10F), Brushes.BlueViolet, 37, margin_X, kedu);
//画平均线
for (int i = 1; i < 8; i++)
{
gp.DrawLine(new Pen(lineColor), margin_Y - 3, (this._Height - margin_X - margin_Y) / 8F * i + margin_X, this._Width - margin_X, (this._Height - margin_X - margin_Y) / 8F * i + margin_X);
gp.DrawString(((max - min) / 8 * (8 - i)+min).ToString("00") + "", new Font("宋体", 9F), Brushes.BlueViolet, 37, (this._Height - margin_X - margin_Y) / 8F * i + margin_X - 5, kedu);
}
gp.DrawLines(new Pen(Color.Black, 0.5F), linesPoint);
//画边框
gp.DrawRectangle(new Pen(Color.Black, 0.5F), 1, 1, _Width - 2, _Height - 2);
// gp.DrawCurve(new Pen(Color.Black, 0.5F), linesPoint);
ms = new MemoryStream();
bitmap.Save(ms, ImageFormat.Jpeg);
arrImage = ms.ToArray();
gp.Dispose();
return arrImage;
}
}
/// <summary>
/// 控件的宽
/// </summary>
public int Width
{
get { return this._Width; }
set { this._Width = value; }
}
/// <summary>
/// 控件的高
/// </summary>
public int Height
{
get { return this._Height; }
set { this._Height = value; }
}
}
--以上是用户自定义控制的代码,页面部分什么都不用的
--以下是在引用控件的代码
<uc1:Curve ID="Curve1" runat="server" Height="600" Width="800" />
--半成品,将就看看能不能用吧
--------------------编程问答-------------------- 谢谢楼上的大大..
还有个问题.就是不知.怎样..
把统计出来的数据.做为数据源啊.
这个表不是直接可以使用的时间,计数..
哪位大大能现身帮下么.
很急很急~ --------------------编程问答-------------------- 刚改成活的了
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
public partial class Curve : System.Web.UI.UserControl
{
int _Width, _Height;
decimal[] Point;
protected void Page_Load(object sender, EventArgs e)
{
DrawMap image = new DrawMap(_Width, _Height);
//Random Rad = new Random();
//string text = Rad.Next(1000, 9999).ToString();
//Session["Code"] = text;
byte[] ImageBuffer = image.getBitmap(Point);
MemoryStream ms = new MemoryStream(ImageBuffer);
Bitmap bitmap = new Bitmap(ms);
bitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
}
public decimal[] SetPoint
{
set {
Point = value;
}
}
public class DrawMap
{
int _Width, _Height;
public DrawMap(int Width, int Height)
{
this._Width = Width;
this._Height = Height;
}
private Bitmap bitmap;
//图型对象
private Graphics gp;
//使用字体
private Font drawFont;
//内存存储空间(图型)
private MemoryStream ms;
public byte[] getBitmap(decimal[] Datas)
{
byte[] arrImage;
bitmap = new Bitmap(_Width, _Height);
gp = Graphics.FromImage(bitmap);
drawFont = new Font("Arial", 12, FontStyle.Bold);
gp.Clear(Color.FromArgb(249, 247, 221));
int margin_X = 15;
int margin_Y = 40;
Color lineColor = Color.FromArgb(134, 134, 134);
Point[] linesPoint = new Point[Datas.Length];
decimal max, min;
max = Datas.Max();
min = Datas.Min();
//画X轴
gp.DrawLine(new Pen(lineColor), margin_Y - 3, this._Height - margin_Y, this._Width - margin_X, this._Height - margin_Y);
gp.DrawLine(new Pen(lineColor), this._Width - margin_X - 6, this._Height - margin_Y - 6, this._Width - margin_X, this._Height - margin_Y);
gp.DrawLine(new Pen(lineColor), this._Width - margin_X - 6, this._Height - margin_Y + 6, this._Width - margin_X, this._Height - margin_Y);
//画Y轴
gp.DrawLine(new Pen(lineColor), margin_Y, margin_X, margin_Y, this._Height - margin_Y);
gp.DrawLine(new Pen(lineColor), margin_Y, margin_X, margin_Y + 6, margin_X + 6);
gp.DrawLine(new Pen(lineColor), margin_Y, margin_X, margin_Y - 6, margin_X + 6);
decimal csale = (_Height - margin_Y - margin_X) / (max - min);
for (int i = 0; i < Datas.Length; i++)
{
linesPoint[i] = new Point((_Width - margin_X - margin_Y) / Datas.Length * i + margin_Y,
_Height - Convert.ToInt32((Datas[i] - min) * csale) -margin_Y);
//点标记
gp.DrawString(Datas[i].ToString(), new Font("宋体", 10F), Brushes.Purple, linesPoint[i].X + 5, linesPoint[i].Y - 10);
//Y轴刻度
gp.DrawLine(new Pen(lineColor),
(_Width - margin_X - margin_Y) / Datas.Length * i + margin_Y,
this._Height - margin_Y,
(_Width - margin_X - margin_Y) / Datas.Length * i + margin_Y,
this._Height - margin_Y + 3);
gp.DrawString(i.ToString(), new Font("宋体", 10F), Brushes.Purple, linesPoint[i].X - 5, this._Height - margin_Y + 3);
}
StringFormat kedu = new StringFormat(StringFormatFlags.DirectionRightToLeft);
//写Y轴刻度
gp.DrawString(min.ToString(), new Font("宋体", 10F), Brushes.BlueViolet, 37, this._Height - margin_Y - 5, kedu);
gp.DrawString(max.ToString(), new Font("宋体", 10F), Brushes.BlueViolet, 37, margin_X, kedu);
//画平均线
for (int i = 1; i < 8; i++)
{
gp.DrawLine(new Pen(lineColor), margin_Y - 3, (this._Height - margin_X - margin_Y) / 8F * i + margin_X, this._Width - margin_X, (this._Height - margin_X - margin_Y) / 8F * i + margin_X);
gp.DrawString(((max - min) / 8 * (8 - i)+min).ToString("00") + "", new Font("宋体", 9F), Brushes.BlueViolet, 37, (this._Height - margin_X - margin_Y) / 8F * i + margin_X - 5, kedu);
}
gp.DrawLines(new Pen(Color.Black, 0.5F), linesPoint);
//画边框
gp.DrawRectangle(new Pen(Color.Black, 0.5F), 1, 1, _Width - 2, _Height - 2);
// gp.DrawCurve(new Pen(Color.Black, 0.5F), linesPoint);
ms = new MemoryStream();
bitmap.Save(ms, ImageFormat.Jpeg);
arrImage = ms.ToArray();
gp.Dispose();
return arrImage;
}
}
/// <summary>
/// 控件的宽
/// </summary>
public int Width
{
get { return this._Width; }
set { this._Width = value; }
}
/// <summary>
/// 控件的高
/// </summary>
public int Height
{
get { return this._Height; }
set { this._Height = value; }
}
}
--引用的页面与以前一样
--后台代码加点东西 曲线个的各个节点
Curve1.SetPoint = new decimal[] { 20, 10, 40, 30, 88, 50, 80, 70, 90, 23.4M, 13.4M, 54, 46, 65.7M, 34.5M, 24.3M, 24.3M, 65 }; --------------------编程问答-------------------- 我这个曲线图是一组decimal数据,然后放在一张平面上.自己画线的
用时间作节点,那是不行的
曲线图上的只有一个一个的节点. --------------------编程问答-------------------- 谢谢谢谢
正在试验中
补充:.NET技术 , ASP.NET