function DBChartBar(parent){
	var pdiv,obj=document.createElement('div');//创建一个控制节点
	if(parent){pdiv=parent;}else pdiv=document.body;//获取父块
    pdiv.appendChild(obj);
	obj.max=0;
	obj.XLabel=new Array();//x轴刻度标签
    obj.YValue=new Array();//y轴刻度标签
	obj.field=new Array();//y轴
	obj.labelvalue=new Array();//x轴
	obj.count;//记录总数	
	obj.Canvas;
	obj.GetMaxValue=DBCB_maxvalue;  
	obj.DelChildren=DBCB_delchildren; //删除块里的对象
	obj.Coordinate=DBCB_coordinate;//画坐标
	obj.style.height=200;
	obj.style.width=450;
	obj.LabelField = null;//横坐标
	obj.ValueField = null;//纵坐标
	obj.Left = 0;
	obj.Top  = 0;
	obj.DataSet=null;
	obj.SetColor='red';  //颜色设置
	obj.ControlWidth;  // 控制x轴的可视范围
	obj.BarWidth=20;  //柱状的宽度
	obj.YStepCount=10;//y轴刻度数量
	obj.YStepLength=20;//Y轴每一个刻度的长度,默认值
	obj.YLength;//Y轴的长度
	obj.XStepLength=50;//x轴每一个刻度的长度
	obj.XStepCount=8;//x轴刻度数量 
	obj.Show=DBCB_show;
	obj.HandleMessage=DBCB_handlemessage;
	obj.Refresh=DBCB_refresh;
	obj.onpropertychange=DBCB_onpropertychange;//属性变化的事件
    obj.oncontextmenu=div_oncontextmenu;
	return obj;
}
function DBCB_onpropertychange()//属性变化处理
{
  var n=event.propertyName;
  switch(n){
	case 'DataSet':
	  if(this.OldDataSet)this.OldDataSet.RemoveLink(this);//从原来的DATASET中移除
      this.DataSet.LinkObj(this);
	  this.OldDataSet=this.DataSet;
	  break;
  }
}
function DBCB_show(){	
	
	this.GetMaxValue();
	this.Coordinate();
}
function DBCB_coordinate(){
	this.YLength=parseInt(this.style.height);  //根据块的大小来确定y轴的长度	
	var ydiv=document.createElement('div');	//放y轴的块
	this.appendChild(ydiv);	
	this.Canvas=new Canvas(ydiv);        //申明画布	
	var x0=this.style.left;             //坐标原点的相对位置
	var y0=this.YLength;
	this.Canvas.Pen.Color='green';	   //画笔颜色
	this.Canvas.Pen.FontSize='13';     //字体大小
	this.Canvas.MoveTo(0,y0);           
	this.Canvas.LineTo(0,0);             //画y轴
	var lg=8;                           //箭头长度
//	var ypoint=['-2,'+lg,'0,0','2,'+lg];//y轴箭头
//	this.Canvas.PolyLine(ypoint);		
	this.Canvas.Top=-15;                //Y轴标签，valuefield
	this.Canvas.Left=-40;               
	this.Canvas.Textbox(this.DataSet.Fields.Field[this.ValueField].DisplayLabel);
	var sy=y0;                       //y轴上刻度的位置
	var num=this.max/this.YStepCount;//刻度的大小
	var step=0;
	var ysteplength=this.YLength/this.YStepCount;
	for(var i=1;i<this.YStepCount;i++){
		sy=sy-ysteplength;
		this.Canvas.MoveTo(0,sy);
		this.Canvas.LineTo(-5,sy);
		this.Canvas.Top=sy-7;      //设置标签的位置
		this.Canvas.Left=-35;
		step=step+num;
		this.Canvas.Textbox(Math.round(step));//y轴坐标的标签
	}	

//画x轴
	this.ControlWidth=parseInt(this.style.width);  //根据块的大小控制x轴的显示范围
	var xdiv=document.createElement('div');	   //放x轴和柱状图的块，可滚动
	this.appendChild(xdiv);
	xdiv.style.top=0;
	xdiv.style.left=0;
	xdiv.style.width=this.ControlWidth;      
	xdiv.style.height=this.YLength+50;
	xdiv.style.overflowX='auto';  	
	xdiv.style.position='absolute';
	this.Canvas.FrameDiv=xdiv;
    this.XStepCount=this.count;                 //总记录数
	var x=this.XStepLength*(this.XStepCount+1); //x轴的长度	
	this.Canvas.MoveTo(0,y0); 
	this.Canvas.LineTo(x,y0); 
//	var xpoint=[(x-lg)+','+(y0-2) ,x+','+y0 ,(x-lg)+','+(y0+2)];//x轴箭头
//	this.Canvas.PolyLine(xpoint);	
	this.Canvas.Top=y0-7;
	this.Canvas.Left=x+5;
	this.Canvas.Textbox(this.DataSet.Fields.Field[this.LabelField].DisplayLabel);

	var sx=0;                                 //x轴上刻度的位置	
	for(var i=1;i<=this.XStepCount;i++){		
			sx=sx+this.XStepLength;
			this.Canvas.MoveTo(sx,y0);		
			this.Canvas.LineTo(sx,y0+5);
			this.Canvas.Top=y0+7;            //设置标签的位置
			this.Canvas.Left=sx-7;
			this.Canvas.Textbox(this.labelvalue[i], 20);//x轴坐标的标签
	}
    
	//柱状图
	this.Canvas.Brush.Color=this.SetColor;
	var sx=0;
	var sy=0;
	for(var i=1;i<=this.XStepCount;i++){
		var l=ysteplength*this.YStepCount*this.field[i]/this.max;		
		sx=sx+this.XStepLength;		
		this.Canvas.Top=y0-l;
		this.Canvas.Left=sx-(this.BarWidth/2);
		var title=this.ValueField+':'+this.field[i]+','+this.LabelField+':'+this.labelvalue[i];
		this.Canvas.Rect(this.BarWidth,Math.ceil(l)).title=title;
	}
}
function DBCB_maxvalue(){    
	this.DataSet.AutoControl=false;  //断开
	this.count=this.DataSet.RecordCount;	 
	this.DataSet.First();
	for(var i=1;i<=this.count;i++){
		this.field[i]=this.DataSet.Fields.Field[this.ValueField].Value;
		this.labelvalue[i]=this.DataSet.Fields.Field[this.LabelField].GetValue();
        this.max=Math.max(this.max,this.field[i]);
		this.DataSet.Next();

    }  
  this.DataSet.AutoControl=true;
  this.DataSet.First();
}
function DBCB_handlemessage(send,msg,recno){	
	switch(msg){
		case 0:this.Refresh();break;
		case 1:break;
		case 2:break;
		case 3:break;
		case 4:break;
		case 5:this.Refresh();break;
		case 6:break;
		case 7:this.DelChildren();break;
		case 8:break;
		case 9:break;

	}
}
function DBCB_refresh(){
		this.total=0;      //计算的总数置零
		this.max=0;
		this.DelChildren();			

		this.GetMaxValue();//重新取值
		this.Coordinate(); //重新画坐标	
}

function DBCB_delchildren(){   //删除块中的节点
	var fd=this;	
	var childno;
	while(fd.childNodes.length!=0){
		childno=fd.children(0);
		fd.removeChild(childno);
		childno.removeNode(false);
		}
}