浏览器大全:是一个提供流行浏览器教程、在线学习分享的学习平台!

动态生成柱状图

前几天在网上看了一个老外的生成图片的方法,
感觉非常实用,不敢独享,下面是我整理过的部分源码,
如果需要,给我发邮件地址(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
}
}

根据它大家还可以试一试

相关软件

2345加速浏览器官方版

2345加速浏览器官方版 | 56.2MB

2345加速浏览器官方版

新一代2345加速浏览器采用Chromium和IE双内核,主打极速与安全特性。基于Chromium深度定制,引入网页智能预加载技术,访问网页更快速..

QQ浏览器官方正式版

QQ浏览器官方正式版 | 49.67MB

QQ浏览器官方正式版

QQ浏览器秉承TT浏览器1-4系列方便易用的特点,但技术架构不同,交互和视觉表现也重新设计,采用Chromium内核+IE双内核,让浏览快速稳定...

百度浏览器最新版下载

百度浏览器最新版下载 | 13.3MB

百度浏览器最新版下载

q百度浏览器,是一款简洁轻快、智能懂你的浏览器。依靠百度强大的搜索平台,在满足用户浏览网页的基础上,它整合百度体系业务优势,带给用户更方便的浏览方式功能...

UC浏览器官方正式版

UC浏览器官方正式版 | 44.2MB

UC浏览器官方正式版

UC浏览器(UC Browser)是UC Mobile Limited在2004年8月开发的一款软件,分uc手机浏览器和uc浏览器电脑版。UC浏览器是全球使用量最大的第三方手机浏览器...

猎豹浏览器2022最新版下载

猎豹浏览器2022下载 | 45MB

猎豹浏览器2022最新版下载

猎豹安全浏览器对Chrome的Webkit内核进行了超过100项的技术优化,访问网页速度更快。其具有首创的智能切换引擎,动态选择内核匹配不同网页...

360安全浏览器官方版下载

360安全浏览器下载 | 21.4MB

360安全浏览器官方版下载

360安全浏览器拥有全国最大的恶意网址库,采用恶意网址拦截技术,可自动拦截挂马、欺诈、网银仿冒等恶意网址。独创沙箱技术,在隔离模式即使访问****也不会感染...