web 柱状图 显示

俺们是个新人,不论是对软件,还是人生,都是满新的。工作一年有半。平时想法很多,但是缺乏实干的毅力。很多事情半途而废。

爱好不在软件,在乎数码,笔记本电脑 数码相机 摄影 数码随身听 手机 呼机 商务通 掌上电脑 IQ IP IC卡,通通没有他们的密码。。。

最近突然想到web上经常要根据数据显示柱状图。

想想应该不难。

主要是了解则么在web上绘图。经过一个2个小时的努力,做出个半途而废的东西。这个东西好好写,再写工整些,写强些。写配置,应该是个不错的东西。

我肯定是半途而废的人嘛。呵呵

None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Web;
None.gif
using  System.Web.SessionState;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.IO;  
None.gif
using  System.Drawing.Imaging;  
None.gif
None.gif
None.gif
namespace  gdi
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// WebForm1 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class WebForm1 : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected System.Web.UI.WebControls.DataGrid DataGrid1;
InBlock.gif    
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面    
InBlock.gif
            DataTable _DT = new DataTable("Test");
InBlock.gif
InBlock.gif            DataColumn _dc 
= new DataColumn();
InBlock.gif            DataColumn myDataColumn;
InBlock.gif            DataRow myDataRow;
InBlock.gif 
InBlock.gif            
// Create first column and add to the DataTable.
InBlock.gif
            myDataColumn = new DataColumn();
InBlock.gif            myDataColumn.DataType
= System.Type.GetType("System.Int32");
InBlock.gif            myDataColumn.ColumnName 
= "Number";            
InBlock.gif            myDataColumn.Caption 
= "ID";
InBlock.gif            myDataColumn.ReadOnly 
= true;            
InBlock.gif            
// Add the column to the DataColumnCollection.
InBlock.gif
            _DT.Columns.Add(myDataColumn);
InBlock.gif 
InBlock.gif            
// Create second column.
InBlock.gif
            myDataColumn = new DataColumn();
InBlock.gif            myDataColumn.DataType
= System.Type.GetType("System.String");
InBlock.gif            myDataColumn.ColumnName 
= "Item";
InBlock.gif            myDataColumn.AutoIncrement 
= false;
InBlock.gif            myDataColumn.Caption 
= "Item";
InBlock.gif            myDataColumn.ReadOnly 
= false;
InBlock.gif            myDataColumn.Unique 
= false;
InBlock.gif            _DT.Columns.Add(myDataColumn); 
InBlock.gif        
InBlock.gif            
// Create three sets of DataRow objects, five rows each, and add to DataTable.
InBlock.gif
            myDataRow = _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 67;
InBlock.gif            myDataRow[
"Item"= "Item0";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 34;
InBlock.gif            myDataRow[
"Item"= "Item1";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 68;
InBlock.gif            myDataRow[
"Item"= "Item2";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 89;
InBlock.gif            myDataRow[
"Item"= "Item3";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 78;
InBlock.gif            myDataRow[
"Item"= "Item3";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 56;
InBlock.gif            myDataRow[
"Item"= "Item4";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 45;
InBlock.gif            myDataRow[
"Item"= "Item5";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 34;
InBlock.gif            myDataRow[
"Item"= "Item6";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 2;
InBlock.gif            myDataRow[
"Item"= "Item7";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 24;
InBlock.gif            myDataRow[
"Item"= "Item8";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 94;
InBlock.gif            myDataRow[
"Item"= "Item9";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 35;
InBlock.gif            myDataRow[
"Item"= "Item10";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 94;
InBlock.gif            myDataRow[
"Item"= "Item11";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 39;
InBlock.gif            myDataRow[
"Item"= "Item12";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 43;
InBlock.gif            myDataRow[
"Item"= "Item13";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 56;
InBlock.gif            myDataRow[
"Item"= "Item14";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif
InBlock.gif            myDataRow 
= _DT.NewRow();
InBlock.gif            myDataRow[
"Number"= 89;
InBlock.gif            myDataRow[
"Item"= "Item15";
InBlock.gif            _DT.Rows.Add(myDataRow);
InBlock.gif                    
InBlock.gif
InBlock.gif            
//this.DataGrid1.DataSource = _DT;
InBlock.gif            
//this.DataGrid1.DataBind();
InBlock.gif

InBlock.gif
InBlock.gif            
this.DrawBlockWithDataTable(_DT);
InBlock.gif        
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif
InBlock.gif        
public void DrawBlockWithDataTable(DataTable _DT)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Bitmap newBitmap 
= null;            
InBlock.gif            Graphics g 
= null ;  
InBlock.gif
InBlock.gif            
try  
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{  
InBlock.gif                Font fontCounter 
= new Font("Lucida Sans Unicode"12);  
InBlock.gif   
InBlock.gif                
//draw the background 
InBlock.gif
                newBitmap = new Bitmap(640,480,PixelFormat.Format32bppPArgb);            
InBlock.gif                
InBlock.gif                g 
= Graphics.FromImage(newBitmap);
InBlock.gif    
InBlock.gif                
//"o" point position
InBlock.gif
                Point _OPoint = new Point();
InBlock.gif                _OPoint.X
=40;
InBlock.gif                _OPoint.Y
=440;
InBlock.gif
InBlock.gif                
//"x" point position
InBlock.gif
                Point _XPoint = new Point();
InBlock.gif                _XPoint.X
=560;
InBlock.gif                _XPoint.Y
=440;
InBlock.gif
InBlock.gif                
//"y" point position
InBlock.gif
                Point _YPoint = new Point();
InBlock.gif                _YPoint.X 
= 40;
InBlock.gif                _YPoint.Y 
= 40;
InBlock.gif                
InBlock.gif                
//create a pen
InBlock.gif
                Pen _Pen = new Pen(Color.White,2);            
InBlock.gif
InBlock.gif                
//draw x and y
InBlock.gif
                g.DrawLine(_Pen,_OPoint,_XPoint);
InBlock.gif                g.DrawLine(_Pen,_OPoint,_YPoint);    
InBlock.gif        
InBlock.gif                
//deal with DT
InBlock.gif
                int itemcount = _DT.Rows.Count;
InBlock.gif
InBlock.gif                
//get the max number
InBlock.gif
                int maxNum = 0;
InBlock.gif                
for (int i = 0 ; i < itemcount ;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    maxNum 
= maxNum > (int)_DT.Rows[i][0]?maxNum:(int)_DT.Rows[i][0];
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
int currentNum = 0;
InBlock.gif
InBlock.gif                
int RentHight = 400/maxNum;
InBlock.gif                
int RentBetweenwidth = 20;
InBlock.gif                Point _CurrentPoint 
= new Point();
InBlock.gif                Point _PrePoint 
= new Point();
InBlock.gif                _PrePoint.X 
= 40;
InBlock.gif                _PrePoint.Y 
= 440;
InBlock.gif                
for(int i=0;i<itemcount;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                   currentNum 
= (int)_DT.Rows[i]["Number"];
InBlock.gif                    _CurrentPoint.X 
= (i*10)+40+(i+1)*RentBetweenwidth;
InBlock.gif                    _CurrentPoint.Y 
= 440-currentNum*RentHight;
InBlock.gif                    g.FillRectangle(
new SolidBrush(Color.Green),_CurrentPoint.X,_CurrentPoint.Y,10,currentNum*RentHight);                                        
InBlock.gif                    g.DrawLine(
new Pen(Color.Red),_PrePoint,_CurrentPoint);
InBlock.gif                    _PrePoint.X 
= _CurrentPoint.X;
InBlock.gif                    _PrePoint.Y 
= _CurrentPoint.Y;
InBlock.gif
ExpandedSubBlockEnd.gif                }

InBlock.gif                    
InBlock.gif                MemoryStream tempStream 
= new MemoryStream();  
InBlock.gif                newBitmap.Save(tempStream,ImageFormat.Jpeg);  
InBlock.gif   
InBlock.gif                Response.ClearContent();  
InBlock.gif                Response.ContentType 
= "image/Jpeg";  
InBlock.gif                Response.BinaryWrite(tempStream.ToArray());  
InBlock.gif                Response.End();  
InBlock.gif
InBlock.gif                
InBlock.gif
ExpandedSubBlockEnd.gif            }
  
InBlock.gif            
catch(Exception ex)  
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{  
InBlock.gif                Console.WriteLine(ex.ToString());  
ExpandedSubBlockEnd.gif            }
  
InBlock.gif            
finally  
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{  
InBlock.gif                
if (null != g) g.Dispose();  
InBlock.gif                
if (null != newBitmap) newBitmap.Dispose();  
ExpandedSubBlockEnd.gif            }
  
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

效果图

%E6%95%88%E6%9E%9C%E5%9B%BE.jpg

作为半途而废的人,只会写到这里了。水平太菜了。

代码风格也不好。

对了,最后再说句,有数码方面研究的找偶。

转载于:https://www.cnblogs.com/pzc/archive/2005/01/28/98825.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值