上一篇:关于ASP.Net写注册表权限问题的官方解决方法 >>
动态生成柱状图
感觉非常实用,不敢独享,下面是我整理过的部分源码,
如果需要,给我发邮件地址(xw@oceansoft.com.cn)。
ChartIndex.aspx
<%@ Page language="c#" Codebehind="ChartIndex.aspx.cs" AutoEventWireup="false" Inherits="TT_W.ChartIndex" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 23px; POSITION: absolute; TOP: 22px" cellSpacing="1" cellPadding="1" width="300" border="0">
<TR>
<TD>
<asp:Label id="Label1" runat="server">红色</asp:Label></TD>
<TD>
<asp:TextBox id="t1" runat="server"></asp:TextBox></TD>
<TD></TD>
</TR>
<TR>
<TD>
<asp:Label id="Label2" runat="server">兰色</asp:Label></TD>
<TD>
<asp:TextBox id="t2" runat="server"></asp:TextBox></TD>
<TD></TD>
</TR>
<TR>
<TD>
<asp:Label id="Label3" runat="server">黄色</asp:Label></TD>
<TD>
<asp:TextBox id="t3" runat="server"></asp:TextBox></TD>
<TD></TD>
</TR>
<TR>
<TD></TD>
<TD>
<asp:Button id="Button1" runat="server" Text="显示例图" Width="75px"></asp:Button></TD>
<TD></TD>
</TR>
<TR>
<TD vAlign="top" align="left" colSpan="3">
<img src="ShowImage.aspx?V1=<%=m_t1%>&V2=<%=m_t2%>&V3=<%=m_t3%>" width=200 height=200></TD>
</TR>
</TABLE>
</FONT>
</form>
</body>
</HTML>
ChartIndex.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace TT_W
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class ChartIndex : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox t1;
protected System.Web.UI.WebControls.TextBox t2;
protected System.Web.UI.WebControls.TextBox t3;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Button Button1;
public Single m_t1;
public Single m_t2;
public Single m_t3;
private void Page_Load(object sender, System.EventArgs e)
{
if(t1.Text!="")
{
m_t1 = Convert.ToSingle(t1.Text);
}
if(t2.Text!="")
{
m_t2 = Convert.ToSingle(t2.Text);
}
if(t3.Text!="")
{
m_t3 = Convert.ToSingle(t3.Text);
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
ShowImage.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace TT_W
{
/// <summary>
/// ShowImage 的摘要说明。
/// </summary>
public class ShowImage : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
if(Request.QueryString["V1"] != null && Request.QueryString["V1"] != "")
{
Bitmap m_bmp = new Bitmap(200,200);
Graphics m_gp = Graphics.FromImage(m_bmp);
SolidBrush redbrush = new SolidBrush(Color.Red);
SolidBrush yellowbrush = new SolidBrush(Color.Yellow);
SolidBrush bluebrush = new SolidBrush(Color.Blue);
SolidBrush whitebrush = new SolidBrush(Color.White);
Pen blackpen = new Pen(Color.Black,2);
m_gp.FillRectangle(whitebrush,0,0,200,200);
m_gp.DrawLine(blackpen,new Point(0,195),new Point(195,195));
m_gp.DrawLine(blackpen,new Point(5,5),new Point(5,200));
Single m_tt = 1;
Single m_t1 = Convert.ToSingle(Request.QueryString["V1"]);
Single m_t2 = Convert.ToSingle(Request.QueryString["V2"]);
Single m_t3 = Convert.ToSingle(Request.QueryString["V3"]);
Single m_h1 = 1;
Single m_h2 = 1;
Single m_h3 = 1;
if(m_t1>m_t2)
{
m_tt = m_t1;
}
else
{
m_tt = m_t2;
}
if(m_tt>m_t3)
{}
else
{
m_tt = m_t3;
}
if(m_tt == 0)
{
m_tt =1;
}
m_h1 = (m_t1/m_tt) * 190;
m_h2 = (m_t2/m_tt) * 190;
m_h3 = (m_t3/m_tt) * 190;
m_gp.FillRectangle(redbrush,10,194-m_h1,50,m_h1);
m_gp.FillRectangle(yellowbrush,70,194-m_h2,50,m_h2);
m_gp.FillRectangle(bluebrush,130,194-m_h3,50,m_h3);
Response.ContentType = "image/gif";
m_bmp.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Gif);
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
根据它大家还可以试一试生成饼状图。 ^o^
下一篇:一个SDK里做聊天室的例子(2) >>
相关文章:
- · 在Webcontrol的Toolbar上加入删除确认的方法(改进后)
- · TreeView 派生类: TreeViewEx 实现 NodeShowToolTip、NodeDoubleClick 事件
- · 我自己写的自定义Web的上传控件
- · 增加判断文字长度,汉字算2个
- · 客户端脚本对中文的验证(javascript)
- · 献丑了,我的asp.net网站开发经验,欢迎参加讨论。
- · 笑望人生,关于IHttpHandler处理图片
- · HTML在线编辑器--服务器控件~~.NET实现~~
- · How to Share Session State Between Classic ASP and ASP.NET(1)
- · How to Share Session State Between Classic ASP and ASP.NET(2)
- · 关于验证控件,希望对和我原来有疑惑的朋友有帮助(刚找的资料,结合猫猫的)
- · 上次的一个问题我打了微软的求助电话,他们也没有办法!
- · [技巧]DataGird的hyper column的url field 绑定两个字段
- · ms--help
- · 续
- · Simple Paging in Repeater and DataList Controls
- · ASP.NET编程中的十大技巧(建议进精华)
- · 转贴:DataGrid/DataList
- · 用ASP.NET写你自己的代码生成器(1)。
- · ASP.NET中Cookie编程的基础知识(6)
- · ASP.NET中Cookie编程的基础知识(5)
- · ASP.NET中Cookie编程的基础知识(4)
- · ASP.NET中Cookie编程的基础知识(3)
- · ASP.NET中Cookie编程的基础知识(2)
- · ASP.NET中Cookie编程的基础知识(1)
- · .NET中窗体间相互访问的几种方式
- · .net中PictureBox中图片的拖动
- · 在.NET上如何根据字符串动态创建控件
- · .NET 窗体之间的交互
- · 使用UltraWinGrid时双击的处理
- · .Net 下的Wondows窗体常用项目
- · 在.net中实现与ASP完全兼容的MD5算法(包括中文字符)
- · .Net FrameWork SDK文档的例子演示
- · 利用.NET语言开发自己的脚本语言(一)
- · .NET中的数据类型的一些变化
- · 网上发现的文章(测试驱动开发)
- · .NET程序实现多语言
- · .NET Framework中使用XML Web Service(2)
