尝试ASP.NET绘图失败后,改用VML来绘制柱状图,饼图和折线图。其中,柱状图又分了两类,普通的柱状图和分组柱状图。调用的函数分别为:drawBars,drawGroupBars,drawPie,drawLines
参数说明在注释中有详细的解释。
/*****************************************
函数名称:VMLImage
函数说明:定义VMLImage类
传入参数:VMLImage的位置参数
  left :左边距
  top  :右边距
  width :宽度
  height :高度
  xDesc :X轴的描述信息
  yDesc :Y轴的描述信息
  zeroBased:坐标数据是否从0算起
返回:新定义的VMLImage对象
*****************************************/
function VMLImage(left,top,width,height,xDesc,yDesc,zeroBased)
{
 this.left = left;
 this.top = top;
 this.width = width;
 this.height = height;
 this.xDesc = xDesc;
 this.yDesc = yDesc;
 this.position = "bottom"; //控制显示描述信息的位置
 this.zeroBased = zeroBased==null?true:zeroBased;
 return this;
}
/**********************************************************
函数名称:drawBars
函数说明:绘制柱状图
传入参数:
  vmlImage :VMLImage对象参数,包含了VML图形的宽度,高度,边距等参数信息
  columnWidth :柱状图中每个柱子的宽度
  dataDesc :数组,描述每个数据代表的意义描述信息
  dataArray :绘制图形的数据值
返回:无
***********************************************************/
function drawBars(vmlImage,columnWidth,dataDesc,dataArray)

 if(dataArray==null||dataArray.length==0) return;
 
 offsetLeft = vmlImage.left;
 offsetTop = vmlImage.top;
 canvasWidth = vmlImage.width;
 canvasHeight = vmlImage.height;
 xDesc = vmlImage.xDesc;
 yDesc = vmlImage.yDesc;
 
 var spaceSpan = 15; //距离坐标轴两端的空间
 //只有一组数据的时候居中显示
 if(dataArray.length==1)
  spaceSpan = spaceSpan = (canvasWidth - dataDesc.length * columnWidth )/2;
 var yCoordCount = 10; //对Y轴进行均分的数目
 
 var maxValue=getMaxValue(dataArray);
 var minValue =getMinValue(dataArray);
 var baseValue=0;
 if(!vmlImage.zeroBased)
 {
  baseValue = minValue-((maxValue - minValue)/(yCoordCount-1));
  if(baseValue==maxValue)
   baseValue=0;
 }
 
 var divImage = document.createElement("<div style='z-index:100;' width:"+eval(canvasWidth-50)+"px;height:"+eval(canvasHeight+50)+"px></div>");
 var eleRect = null;
 
 //画背景图
 eleRect = document.createElement("<v:rect style='position:absolute;left:"+offsetLeft+"px;top:"+eval(offsetTop-10)+"px;width:"+canvasWidth+"px;height:"+eval(canvasHeight+10)+"px;z-index:-1' fillcolor='#9cf' stroked='f'></v:rect>");
 eleRect.appendChild(document.createElement("<v:fill rotate='t' angle='-45' focus='100%' type='gradient'/>"));
 divImage.insertBefore(eleRect);
 
 //The plus 20px used for end arrow
 var originalPoint = new Point(offsetLeft,canvasHeight+offsetTop);
 var xEndPoint = new Point(offsetLeft + canvasWidth + 20,originalPoint.y);
 var yEndPoint = new Point(offsetLeft,offsetTop-20);
 
 var eleShape = null;
 var eleTextBox = null;
 //画横坐标轴 X轴
 var eleLine = document.createElement("<v:line  alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+originalPoint.x+"px,"+originalPoint.y+"px' to='"+xEndPoint.x+"px,"+xEndPoint.y+"px'></v:line>");
 eleLine.appendChild(document.createElement("<v:stroke endarrow='classic' weight='1px'/>"));
 divImage.appendChild(eleLine);
 //标注X轴的描述
 eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(offsetLeft+canvasWidth) + "px;top:" + eval(offsetTop+canvasHeight+10) + "px;width:" + 60 + "px;height:18px;z-index:1'></v:shape>");
 eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
 eleTextBox.innerHTML ="<table cellspacing='3' border='0' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + xDesc + "</td></tr></table>";
 eleShape.appendChild(eleTextBox);
 divImage.appendChild(eleShape);
 
 //画纵坐标轴 Y轴
 eleLine = document.createElement("<v:line alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1'  from='"+originalPoint.x+","+originalPoint.y+"px' to='"+yEndPoint.x+"px,"+yEndPoint.y+"px'></v:line>");
 eleLine.appendChild(document.createElement("<v:stroke startarrow='classic' weight='1px'/>"));
 divImage.appendChild(eleLine);
 //标注Y轴的描述
 eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(offsetLeft+10) + "px;top:" + eval(offsetTop-30) + "px;width:" + 60 + "px;height:18px;z-index:1'></v:shape>");
 eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
 eleTextBox.innerHTML ="<table cellspacing='3' border='0' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + yDesc + "</td></tr></table>";
 eleShape.appendChild(eleTextBox);
 divImage.appendChild(eleShape);
 
 //画三维背景 cornerPoint.x=280 cornerPoint.y=240
 var cornerPoint = new Point(offsetLeft + 10, canvasHeight + offsetTop - 10);
 
 divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+cornerPoint.x+"px,"+eval(offsetTop-10)+"px' to='"+cornerPoint.x+"px,"+cornerPoint.y+"px' strokecolor='#69f'/>"));
 divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' to='"+offsetLeft+"px,"+cornerPoint.y+"px' from='"+cornerPoint.x+"px,"+eval(offsetTop+canvasHeight)+"px' strokecolor='#69f'/>"));
 divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+cornerPoint.x+"px,"+cornerPoint.y+"px' to='"+eval(canvasWidth+offsetLeft)+"px,"+cornerPoint.y+"px' strokecolor='#69f'/>"));
 
 //画纵坐标 Y轴,均分为10等份
 var stepHeight = canvasHeight / yCoordCount;
 
 var leftEnd = offsetLeft -8;//坐标刻度的长度
 
 divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+offsetLeft+"px,"+eval(offsetTop-10)+"px' to='"+eval(offsetLeft+10)+"px,"+eval(offsetTop)+"px' strokecolor='#69f'/>"));
   divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+eval(offsetLeft+10)+"px,"+eval(offsetTop-10)+"px' to='"+eval(canvasWidth+offsetLeft)+"px,"+eval(offsetTop-10)+"px' strokecolor='#69f'/>"));
   divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+offsetLeft+"px,"+offsetTop+"px' to='"+leftEnd+"px,"+eval(offsetTop)+"px'/>"));
 for(var i=1;i< yCoordCount ;i++)
 {
  var spanHeight = offsetTop + canvasHeight - stepHeight*i -10 ;
  divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+offsetLeft+"px,"+spanHeight+"px' to='"+eval(offsetLeft+10)+"px,"+eval(spanHeight+10)+"px' strokecolor='#69f'/>"));
  divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+eval(offsetLeft+10)+"px,"+spanHeight+"px' to='"+eval(canvasWidth+offsetLeft)+"px,"+spanHeight+"px' strokecolor='#69f'/>"));
  divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+offsetLeft+"px,"+eval(spanHeight+10)+"px' to='"+leftEnd+"px,"+eval(spanHeight+10)+"px'/>"));
 }
 
 /******************************
    画柱状图的主体部分
 ******************************/
 //获得数据的缩放比率
 if(baseValue>0)
  maxValue -= baseValue;
 var ratio = canvasHeight/ maxValue;
 var newData = resetValue(ratio,baseValue,dataArray);
 
 /**********************************************
    标示数据在坐标轴
 **********************************************/
 var stepValue = maxValue / yCoordCount;
 for(var i=0;i<=yCoordCount;i++)
 {
  var spanHeight = offsetTop + canvasHeight - stepHeight*i -10 ;
  eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(offsetLeft-70) + "px;top:" + spanHeight + "px;width:" + 60 + "px;height:18px;z-index:1'></v:shape>");
  eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
  eleTextBox.innerHTML ="<table cellspacing='3' border='0' cellpadding='0' width='100%' height='100%'><tr><td align='right'>" + Math.round(eval(stepValue*i+baseValue)) + "</td></tr></table>";
  eleShape.appendChild(eleTextBox);
  divImage.appendChild(eleShape);
 }
 //柱子的数目
 var columnCount = dataArray.length;
 //获得柱子之间的间距
 var columnSpan=null;
 if(columnCount==1)
  columnSpan=spaceSpan;
 else
  columnSpan = (canvasWidth - spaceSpan*2 - columnCount * columnWidth)/(columnCount-1);
 //起画点坐标
 var leftStart = offsetLeft + spaceSpan;
 for(var i=0;i<columnCount;i++)
 {
  var topVal = canvasHeight + offsetTop - newData[i];
  var heightVal = newData[i];
  var columnColor = getColor(i);
  var eleRect = document.createElement("<v:rect style='position:absolute;left:"+leftStart+"px;top:"+topVal+"px;width:"+columnWidth+";height:"+heightVal+"px;z-index:1' fillcolor='"+columnColor.color1+"'></v:rect>");
  eleRect.appendChild(document.createElement("<v:fill color2='"+columnColor.color2+"' rotate='t' type='gradient'/>"));
  eleRect.appendChild(document.createElement("<o:extrusion v:ext='view' backdepth='20pt' color='"+columnColor.color1+"' on='t'/>"));
   
  
  //画柱状图上面的数据
  eleShape = document.createElement("<v:shape style='position:absolute;left:"+leftStart+"px;top:" +eval(topVal-25)+ "px;width:" + (columnWidth+15) + "px;height:18px;z-index:1'></v:shape>");
  eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
  eleTextBox.innerHTML = "<table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='center'>" + dataArray[i] + "</td></tr></table>";
  eleShape.appendChild(eleTextBox);
  divImage.appendChild(eleRect);
  divImage.appendChild(eleShape);   
    
    //画柱状图下面标示的名称
    eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(leftStart - columnWidth/2) + "px;top:" + eval(canvasHeight + offsetTop) + "px;width:" + eval(columnWidth+columnSpan) + "px;height:18px;z-index:1'></v:shape>");
  eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
  eleTextBox.innerHTML= "<table cellspacing='3' cellpadding='0'><tr><td align='center'>" + dataDesc[i] + "</td></tr></table>"
  eleShape.appendChild(eleTextBox);
  divImage.appendChild(eleShape);
  
  leftStart += columnWidth+columnSpan;
 }
 document.body.appendChild(divImage);
}
/**********************************************************
函数名称:drawGroupBars
函数说明:绘制分组柱状图
传入参数:
  vmlImage :VMLImage对象,包含了宽度,高度,边距等参数
  columnWidth :柱状图中每个柱子的宽度
  dataDesc :数据信息描述
  groupDesc :分组信息描述
  dataArray :二维数组,内容为分组数据的数组
返回:无
***********************************************************/
function drawGroupBars(vmlImage,columnWidth,dataDesc,groupDesc,dataArray)
{
 if(dataArray==null || dataArray.length==0) return;
 offsetLeft = vmlImage.left;
 offsetTop = vmlImage.top;
 canvasWidth = vmlImage.width;
 canvasHeight = vmlImage.height;
 xDesc = vmlImage.xDesc;
 yDesc = vmlImage.yDesc;
 
 var spaceSpan = 15; //距离坐标轴两端的空间
 //只有一组数据的时候居中显示
 if(dataArray.length==1)
  spaceSpan = spaceSpan = (canvasWidth - dataDesc.length * columnWidth )/2;
 
 var yCoordCount = 10; //对Y轴进行均分的数目
 var maxValue=0;
 for(var i=0;i<dataArray.length;i++)
 {
  var tmpMaxValue = getMaxValue(dataArray[i]);
  if(tmpMaxValue > maxValue) maxValue = tmpMaxValue;
 }
 
 var minValue =dataArray[0][0];
 for(var i=0;i<dataArray.length;i++)
 {
  var tmpMinValue = getMinValue(dataArray[i]);
  if(tmpMinValue < minValue) minValue = tmpMinValue;
 }
 //判断是否从0开始算坐标
 var baseValue=0;
 if(!vmlImage.zeroBased)
 {
  baseValue = minValue-((maxValue - minValue)/(yCoordCount-1));
  if(baseValue==maxValue)
   baseValue=0;
 }
 
 var divImage = document.createElement("<div style='z-index:100;' width:"+eval(canvasWidth-50)+"px;height:"+eval(canvasHeight+50)+"px></div>");
 
 //画背景图
 var eleBackRect = document.createElement("<v:rect style='position:absolute;left:"+offsetLeft+"px;top:"+eval(offsetTop-10)+"px;width:"+canvasWidth+"px;height:"+eval(canvasHeight+10)+"px;z-index:-1' fillcolor='#9cf' stroked='f'></v:rect>");
 
 eleBackRect.appendChild(document.createElement("<v:fill rotate='t' angle='-45' focus='100%' type='gradient'/>"));
 divImage.insertBefore(eleBackRect);
 
 //The plus 20px used for end arrow
 var originalPoint = new Point(offsetLeft,canvasHeight+offsetTop);
 var xEndPoint = new Point(offsetLeft + canvasWidth + 20,originalPoint.y);
 var yEndPoint = new Point(offsetLeft,offsetTop-20);
 
 var eleShape=null;
 var eleTextBox = null;
 //画横坐标轴 X轴
 var eleLine = document.createElement("<v:line  alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+originalPoint.x+"px,"+originalPoint.y+"px' to='"+xEndPoint.x+"px,"+xEndPoint.y+"px'></v:line>");
 eleLine.appendChild(document.createElement("<v:stroke endarrow='classic' weight='1px'/>"));
 divImage.appendChild(eleLine);
 //标注X轴的描述
 eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(offsetLeft+canvasWidth) + "px;top:" + eval(offsetTop+canvasHeight+10) + "px;width:" + 60 + "px;height:18px;z-index:1'></v:shape>");
 eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
 eleTextBox.innerHTML ="<table cellspacing='3' border='0' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + xDesc + "</td></tr></table>";
 eleShape.appendChild(eleTextBox);
 divImage.appendChild(eleShape);
 //画纵坐标轴 Y轴
 eleLine = document.createElement("<v:line alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1'  from='"+originalPoint.x+","+originalPoint.y+"px' to='"+yEndPoint.x+"px,"+yEndPoint.y+"px'></v:line>");
 eleLine.appendChild(document.createElement("<v:stroke startarrow='classic' weight='1px'/>"));
 divImage.appendChild(eleLine);
 //标注Y轴的描述
 eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(offsetLeft+10) + "px;top:" + eval(offsetTop-30) + "px;width:" + 60 + "px;height:18px;z-index:1'></v:shape>");
 eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
 eleTextBox.innerHTML ="<table cellspacing='3' border='0' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + yDesc + "</td></tr></table>";
 eleShape.appendChild(eleTextBox);
 divImage.appendChild(eleShape);
 
 //画三维背景 cornerPoint.x=280 cornerPoint.y=240
 var cornerPoint = new Point(offsetLeft + 10, canvasHeight + offsetTop - 10);
 
 divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+cornerPoint.x+"px,"+eval(offsetTop-10)+"px' to='"+cornerPoint.x+"px,"+cornerPoint.y+"px' strokecolor='#69f'/>"));
 divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' to='"+offsetLeft+"px,"+cornerPoint.y+"px' from='"+cornerPoint.x+"px,"+eval(offsetTop+canvasHeight)+"px' strokecolor='#69f'/>"));
 divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+cornerPoint.x+"px,"+cornerPoint.y+"px' to='"+eval(canvasWidth+offsetLeft)+"px,"+cornerPoint.y+"px' strokecolor='#69f'/>"));
 
 //画纵坐标 Y轴,均分为10等份
 var stepHeight = canvasHeight / yCoordCount;
 
 var leftEnd = offsetLeft -8;//坐标刻度的长度
 
 divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+offsetLeft+"px,"+eval(offsetTop-10)+"px' to='"+eval(offsetLeft+10)+"px,"+eval(offsetTop)+"px' strokecolor='#69f'/>"));
 divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+eval(offsetLeft+10)+"px,"+eval(offsetTop-10)+"px' to='"+eval(canvasWidth+offsetLeft)+"px,"+eval(offsetTop-10)+"px' strokecolor='#69f'/>"));
 divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+offsetLeft+"px,"+offsetTop+"px' to='"+leftEnd+"px,"+eval(offsetTop)+"px'/>"));
 for(var i=1;i< yCoordCount ;i++)
 {
  var spanHeight = offsetTop + canvasHeight - stepHeight*i -10 ;
  divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+offsetLeft+"px,"+spanHeight+"px' to='"+eval(offsetLeft+10)+"px,"+eval(spanHeight+10)+"px' strokecolor='#69f'/>"));
  divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+eval(offsetLeft+10)+"px,"+spanHeight+"px' to='"+eval(canvasWidth+offsetLeft)+"px,"+spanHeight+"px' strokecolor='#69f'/>"));
  divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+offsetLeft+"px,"+eval(spanHeight+10)+"px' to='"+leftEnd+"px,"+eval(spanHeight+10)+"px'/>"));
 }
 
 /******************************
  画柱状图的主体部分
 ******************************/
 //获得数据的缩放比率
 if(baseValue > 0)
  maxValue -= baseValue;
 var ratio = canvasHeight/ maxValue;
 
 /**********************************************
    标示数据在坐标轴
 **********************************************/
 var stepValue = maxValue / yCoordCount;
 for(var i=0;i<=yCoordCount;i++)
 {
  var spanHeight = offsetTop + canvasHeight - stepHeight*i -10 ;
  eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(offsetLeft-70) + "px;top:" + spanHeight + "px;width:" + 50 + "px;height:18px;z-index:1'></v:shape>");
  eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
  eleTextBox.innerHTML ="<table cellspacing='3' border='0' cellpadding='0' width='100%' height='100%'><tr><td align='right'>" + Math.round(eval(stepValue*i + baseValue)) + "</td></tr></table>";
  eleShape.appendChild(eleTextBox);
  divImage.appendChild(eleShape);
 }
 
 //绘制柱状图的组数目
 var groupCount = groupDesc.length;
 //每组中包含的柱状图的数目,必须保证每组数据中的数据个数一致!!!
 var columnCount = dataDesc.length;
 //获得柱子之间的间距
 if(groupCount==1)
  columnSpan = spaceSpan;
 else
  columnSpan = (canvasWidth - spaceSpan*2 - columnCount * columnWidth*groupCount)/(groupCount-1);
 //起画点坐标
 var leftStart = offsetLeft + spaceSpan;
 for(var i=0;i<dataArray.length;i++)
 {
  var oldData = dataArray[i];
  var newData = resetValue(ratio,baseValue,oldData);
  for(var j=0;j<columnCount;j++)
  {
   var topVal = canvasHeight + offsetTop - newData[j];
   var heightVal = newData[j];
   var columnColor = getColor(j);
   var eleRect = document.createElement("<v:rect style='position:absolute;left:"+leftStart+"px;top:"+topVal+"px;width:"+columnWidth+";height:"+heightVal+"px;z-index:1' fillcolor='"+columnColor.color1+"'></v:rect>");
   eleRect.appendChild(document.createElement("<v:fill color2='"+columnColor.color2+"' rotate='t' type='gradient'/>"));
   eleRect.appendChild(document.createElement("<o:extrusion v:ext='view' backdepth='20pt' color='"+columnColor.color1+"' on='t'/>"));
   
   //画柱状图上面的数据
   eleShape = document.createElement("<v:shape style='position:absolute;left:"+leftStart+"px;top:" +eval(topVal-25)+ "px;width:" + (columnWidth+15) + "px;height:18px;z-index:1'></v:shape>");
   eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
   eleTextBox.innerHTML = "<table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='center'>" + oldData[j] + "</td></tr></table>";
   eleShape.appendChild(eleTextBox);
   
   divImage.appendChild(eleRect);
   divImage.appendChild(eleShape);
   leftStart += columnWidth;
  }
  
  //画柱状图下面标示的名称
  eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(leftStart - columnWidth*columnCount) + "px;top:" + eval(canvasHeight + offsetTop) + "px;width:" + eval(columnWidth*columnCount +columnSpan) + "px;height:18px;z-index:1'></v:shape>");
  eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
  eleTextBox.innerHTML= "<table cellspacing='3' cellpadding='0'><tr><td align='center'>" + groupDesc[i] + "</td></tr></table>"
  eleShape.appendChild(eleTextBox);
  divImage.appendChild(eleShape);
  
  leftStart += columnSpan;
 }
 //显示数据描述信息
 var rectWidth = 120; //信息框的长度
 if(vmlImage.position.toLowerCase()=="right")
 {
  var x1= offsetLeft + canvasWidth;
  var y1= offsetTop + 30;
  for(var i=0;i<columnCount;i++)
  {  
   var color = getColor(i);
   eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(x1+10)+ "px;top:" + (y1+ i*30) + "px;width:80px;height:" + 30 + "px;z-index:1'></v:shape>");
   eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
   eleTextBox.innerHTML = "<table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + dataDesc[i] + "</td></tr></table>";
    eleShape.appendChild(eleTextBox);
    divImage.appendChild(eleShape);
   divImage.appendChild(document.createElement("<v:rect style='position:absolute;left:" + eval(x1+ rectWidth) + "px;top:" + eval(y1+ i * 30 +3) + "px;width:30px;height:20px;z-index:1' fillcolor='" +color.color1 + "'></v:rect>"));
  }
 }
 else
 {
  var x1= offsetLeft ;
  var y1= offsetTop+canvasHeight+30;
  var rowNum = 1;
  for(var i=0;i<columnCount;i++)
  {  
  var color = getColor(i);
  
  eleShape = document.createElement("<v:shape style='position:absolute;left:" + x1+ "px;top:" + y1 + "px;width:"+eval(rectWidth+40)+"px;height:" + 30 + "px;z-index:1'></v:shape>");
  eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
  eleTextBox.innerHTML = "<table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + dataDesc[i] + "</td></tr></table>";
   eleShape.appendChild(eleTextBox);
   divImage.appendChild(eleShape);
  divImage.appendChild(document.createElement("<v:rect style='position:absolute;left:" + eval(x1+rectWidth) + "px;top:" + eval(y1+5) + "px;width:30px;height:20px;z-index:1' fillcolor='" +color.color1 + "'></v:rect>"));
  if(rectWidth * (i+1) +50 >=canvasWidth)
  {
   x1 = offsetLeft;
   rowNum ++;
   y1 += rowNum * 30;
  }
  else
   x1 += rectWidth + 50;
  }
 }
 
 document.body.appendChild(divImage);
}
/**********************************************************
函数名称:drawLines
函数说明:画折线图
传入参数:
  vmlImage :VMLImage对象,包含图形的宽度,高度,边距参数
  dataDesc :数据信息描述
  groupDesc :分组信息描述
  dataArray :二维数组,内容保存点数据的数组
返回:无
***********************************************************/
function drawLines(vmlImage,dataDesc,groupDesc,dataArray)
{
 if(dataArray==null || dataArray.length==0) return;
 offsetLeft = vmlImage.left;
 offsetTop = vmlImage.top;
 canvasWidth = vmlImage.width;
 canvasHeight = vmlImage.height;
 xDesc = vmlImage.xDesc;
 yDesc = vmlImage.yDesc;
 
 var yCoordCount = 10; //对Y轴进行均分的数目
 var spaceSpan = 15; //距离坐标轴右端的空间
 var maxValue=0;
 for(var i=0;i<dataArray.length;i++)
 {
  var tmpMaxValue = getMaxValue(dataArray[i]);
  if(tmpMaxValue > maxValue) maxValue = tmpMaxValue;
 }
 
 var minValue =dataArray[0][0];
 for(var i=0;i<dataArray.length;i++)
 {
  var tmpMinValue = getMinValue(dataArray[i]);
  if(tmpMinValue < minValue) minValue = tmpMinValue;
 }
 //判断是否从0开始算坐标
 var baseValue=0;
 if(!vmlImage.zeroBased)
 {
  baseValue = minValue-((maxValue - minValue)/(yCoordCount-1));
  if(baseValue==maxValue)
   baseValue=0;
 }
 
 var divImage = document.createElement("<div style='z-index:100;' width:"+eval(canvasWidth-50)+"px;height:"+eval(canvasHeight+50)+"px></div>");
 var eleRect = null;
 //画背景图
 eleRect = document.createElement("<v:rect style='position:absolute;left:"+offsetLeft+"px;top:"+offsetTop+"px;width:"+canvasWidth+"px;height:"+canvasHeight+"px;z-index:-1' fillcolor='#9cf' stroked='f'></v:rect>");
 eleRect.appendChild(document.createElement("<v:fill rotate='t' angle='-45' focus='100%' type='gradient'/>"));
 divImage.appendChild(eleRect);
 
 //The plus 20px used for end arrow
 var originalPoint = new Point(offsetLeft,canvasHeight+offsetTop);
 var xEndPoint = new Point(offsetLeft + canvasWidth + 20,originalPoint.y);
 var yEndPoint = new Point(offsetLeft,offsetTop-20);
 
 var eleShape=null;
 var eleTextBox = null;
 //画横坐标轴 X轴
 var eleLine = document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+originalPoint.x+"px,"+originalPoint.y+"px' to='"+xEndPoint.x+"px,"+xEndPoint.y+"px'></v:line>");
 eleLine.appendChild(document.createElement("<v:stroke endarrow='classic' weight='1px'/>"));
 divImage.appendChild(eleLine);
 //标注X轴的描述
 eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(offsetLeft+canvasWidth) + "px;top:" + eval(offsetTop+canvasHeight+10) + "px;width:" + 60 + "px;height:18px;z-index:1'></v:shape>");
 eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
 eleTextBox.innerHTML ="<table cellspacing='3' border='0' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + xDesc + "</td></tr></table>";
 eleShape.appendChild(eleTextBox);
 divImage.appendChild(eleShape);
 
 //画纵坐标轴 Y轴
 eleLine = document.createElement("<v:line alt='' style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1'  from='"+originalPoint.x+","+originalPoint.y+"px' to='"+yEndPoint.x+"px,"+yEndPoint.y+"px'></v:line>");
 eleLine.appendChild(document.createElement("<v:stroke startarrow='classic' weight='1px'/>"));
 divImage.appendChild(eleLine);
 //标注Y轴的描述
 eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(offsetLeft+10) + "px;top:" + eval(offsetTop-30) + "px;width:" + 60 + "px;height:18px;z-index:1'></v:shape>");
 eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
 eleTextBox.innerHTML ="<table cellspacing='3' border='0' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + yDesc + "</td></tr></table>";
 eleShape.appendChild(eleTextBox);
 divImage.appendChild(eleShape);
    
 //画纵坐标 Y轴,均分为10等份
 var stepHeight = canvasHeight / yCoordCount;
 
 var leftEnd = offsetLeft -8;//坐标刻度的长度
 
 for(var i=1;i<= yCoordCount ;i++)
 {
  var spanHeight = offsetTop + canvasHeight - stepHeight*i;
  divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+offsetLeft+"px,"+spanHeight+"px' to='"+eval(canvasWidth+offsetLeft)+"px,"+spanHeight+"px' strokecolor='#69f'/>"));
  divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;flip:y;z-index:-1' from='"+offsetLeft+"px,"+spanHeight+"px' to='"+leftEnd+"px,"+spanHeight+"px'/>"));
 }
 /******************************
   画折线图的主体部分
 ******************************/
 //获得数据的缩放比率
 var ratio = canvasHeight/ maxValue;
 /**********************************************
    标示数据在纵坐标轴
 **********************************************/
 if(baseValue>0)
  maxValue -= baseValue;
 var stepValue = maxValue / yCoordCount;
 for(var i=0;i<=yCoordCount;i++)
 {
  var spanHeight = offsetTop + canvasHeight - stepHeight*i-10 ;
  eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(offsetLeft-70) + "px;top:" + spanHeight + "px;width:" + 50 + "px;height:18px;z-index:1'></v:shape>");
  eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
  eleTextBox.innerHTML ="<table cellspacing='3' border='0' cellpadding='0' width='100%' height='100%'><tr><td align='right'>" + Math.round(eval(stepValue*i+baseValue)) + "</td></tr></table>";
  eleShape.appendChild(eleTextBox);
  divImage.appendChild(eleShape);
 }
 
 //坐标点个数,必须确保所有传入的数组长度一致!!!
 var dotCount = dataDesc.length;
 //横坐标之间的坐标点宽度
 var stepWidth = (canvasWidth - spaceSpan)/(dotCount-1);
 //开始画折线
 for(var i=0;i<dataArray.length;i++)
 {
  var newData = resetValue(ratio,baseValue,dataArray[i]);
  var color = getColor(i);
  for(var j=0;j<dotCount-1;j++)
  {
   var x1 = offsetLeft+j*stepWidth;
   var y1 = offsetTop+canvasHeight - newData[j];
    
    var x2 = offsetLeft+(j+1)*stepWidth;
    var y2 = offsetTop+canvasHeight - newData[j+1];
   divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;z-index:1' from='" + x1 + "px," + y1 + "px' to='" + x2 + "px," + y2 + "px' coordsize='21600,21600' strokecolor='" + color.color1 + "' strokeweight='2px'></v:line>"));
   //在线上打实心点
   divImage.appendChild(document.createElement("<v:oval style='position:absolute;left:" + (x1 - 2) + "px;top:" + (y1 - 2) + "px;width:4px;height:4px;z-index:1' fillcolor='" + color.color1 + "' strokecolor='" + color.color1 + "'/>"));
  }
 }
 //在坐标轴下画刻度,标数据
 for(var j=0;j<dotCount;j++)
 {
  var x1 = offsetLeft+j*stepWidth;
  var y1 = offsetTop+canvasHeight;
  divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;z-index:1' from='" + x1 + "px," + y1 + "px' to='" + x1 + "px," + eval(y1+8) + "px'  strokecolor='#000000'></v:line>"));
  eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(x1- stepWidth/2)+ "px;top:" + eval(y1+8) + "px;width:" + stepWidth + "px;height:18px;z-index:1'></v:shape>");
  eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:shape>");
  eleTextBox.innerHTML ="<table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='center'>" + dataDesc[j] + "</td></tr></table>";
  
  eleShape.appendChild(eleTextBox);
  divImage.appendChild(eleShape);
 }
 
 //显示描述信息
 var rectWidth = 120; //信息框的长度
 if(vmlImage.position.toLowerCase()=="right")
 {
  var x1= offsetLeft + canvasWidth;
  var y1= offsetTop + 30;
  for(var i=0;i<groupDesc.length;i++)
  {  
   var color = getColor(i);
   eleShape = document.createElement("<v:shape style='position:absolute;left:" + eval(x1+10)+ "px;top:" + (y1+ i*30) + "px;width:80px;height:" + 30 + "px;z-index:1'></v:shape>");
   eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
   eleTextBox.innerHTML = "<table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + groupDesc[i] + "</td></tr></table>";
    eleShape.appendChild(eleTextBox);
    divImage.appendChild(eleShape);
   divImage.appendChild(document.createElement("<v:rect style='position:absolute;left:" + eval(x1+ rectWidth) + "px;top:" + eval(y1+ i * 30 +3) + "px;width:30px;height:20px;z-index:1' fillcolor='" +color.color1 + "'></v:rect>"));
  }
 }
 else
 {
  var x1= offsetLeft ;
  var y1= offsetTop+canvasHeight+30;
  var rowNum = 1;
  for(var i=0;i<groupDesc.length;i++)
  {  
  var color = getColor(i);
  
  eleShape = document.createElement("<v:shape style='position:absolute;left:" + x1+ "px;top:" + y1 + "px;width:"+eval(rectWidth+40)+"px;height:" + 30 + "px;z-index:1'></v:shape>");
  eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
  eleTextBox.innerHTML = "<table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='left'>" + groupDesc[i] + "</td></tr></table>";
  eleShape.appendChild(eleTextBox);
  divImage.appendChild(eleShape);
  divImage.appendChild(document.createElement("<v:rect style='position:absolute;left:" + eval(x1+rectWidth) + "px;top:" + eval(y1+5) + "px;width:30px;height:20px;z-index:1' fillcolor='" +color.color1 + "'></v:rect>"));
  if(rectWidth * (i+1) +50 >=canvasWidth)
  {
   x1 = offsetLeft;
   rowNum ++;
   y1 += rowNum * 30;
  }
  else
   x1 += rectWidth + 50;
  }
 }
 
 document.body.appendChild(divImage);
}
/**********************************************************
函数名称:drawPie
函数说明:画饼状图
传入参数:
  vmlImage :VMLImage对象,包含图形的宽度,高度和边距参数
  dataDesc :数组,描述每个数据代表的意义
  dataArray :绘制图形的数据值
返回:无
***********************************************************/
function drawPie(vmlImage,dataDesc,dataArray)
{
 offsetLeft = vmlImage.left;
 offsetTop = vmlImage.top;
 canvasWidth = vmlImage.width;
 canvasHeight = vmlImage.height;
 var dataCount = dataDesc.length;
 var totalValue = sumArray(dataArray);
 
 var divImage = document.createElement("<div style='z-index:100;' width:"+eval(canvasWidth-50)+"px;height:"+eval(canvasHeight+50)+"px></div>");
 var PreAngle = 0;
 var eleShape = null;
 var eleTextBox = null;
 for(var i=0;i<dataCount;i++)
 {
  var color = getColor(i);
  eleShape = document.createElement("<v:shape style='position:absolute;left:" + offsetLeft + "px;top:" + offsetTop + "px;width:" + canvasWidth + "px;height:" + canvasHeight + "px;z-index:1' coordsize='1500,1400' o:spt='100' adj='0,,0' path='m750,700ae750,700,750,700," + parseInt(23592960*PreAngle) + "," + parseInt(23592960*dataArray[i]/totalValue) + "xe' fillcolor='" + color.color1 + "' strokecolor='#FFFFFF'></v:shape>");
  eleShape.appendChild(document.createElement("<v:fill color2='" + color.color2 + "' rotate='t' focus='100%' type='gradient'/>"));
  eleShape.appendChild(document.createElement("<v:stroke joinstyle='round'/>"));
  eleShape.appendChild(document.createElement("<v:formulas/>"));
  eleShape.appendChild(document.createElement("<v:path o:connecttype='segments'/>"));
  eleShape.appendChild(document.createElement("<v:extrusion type='view' on='t' backdepth='20' brightness='0.2' rotationangle='0,0' />"));
  divImage.appendChild(eleShape);
  
  PreAngle += dataArray[i] / totalValue;
 }
 var pie = Math.PI;
 var TempPie = 0;
 var startX = offsetLeft + canvasWidth/2;
 var startY = offsetTop + canvasHeight/2;
 
 for(var i=0;i<dataCount;i++)
 {
  var TempAngle = pie * 2 * (dataArray[i] / (totalValue * 2) + TempPie);
  var x1 = startX + Math.cos(TempAngle) * canvasWidth * 3/8;
  var y1 = startY - Math.sin(TempAngle) * canvasHeight * 3/8;
  var x2 = startX + Math.cos(TempAngle) * canvasWidth * 3/4;
  var y2 = startY - Math.sin(TempAngle) * canvasHeight * 3/4;
 
  if(x2>offsetLeft + canvasWidth/2)
  {
  x3 = x2 + 20;
  x4 = x3;
  }
  else
  {
  x3 = x2 - 20;
  x4 = x3 - 100;
  }
  divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;z-index:1' from='" + x1 + "px," + y1 + "px' to='" + x2 + "px," + y2 + "px' coordsize='21600,21600' strokecolor='#111111' strokeweight='1px'></v:line>"));
  divImage.appendChild(document.createElement("<v:line style='position:absolute;left:0;text-align:left;top:0;z-index:1' from='" + x2 + "px," + y2 + "px' to='" + x3 + "px," + y2 + "px' coordsize='21600,21600' strokecolor='#111111' strokeweight='1px'></v:line>"));
  eleShape = document.createElement("<v:shape style='position:absolute;left:" + x4 + "px;top:" + (y2 - 10) + "px;width:100px;height:20px;z-index:1'></v:shape>")
  eleTextBox = document.createElement("<v:textbox inset='0px,0px,0px,0px'></v:textbox>");
  eleTextBox.innerHTML = "<table cellspacing='3' border=0 cellpadding='0' width='100%' height='100%'><tr><td align='center'>" + dataDesc[i] + " " + Math.round(parseFloat(dataArray[i] * 100/ totalValue)*100)/100 + "%</td></tr></table>";
  eleShape.appendChild(eleTextBox);
  divImage.appendChild(eleShape);
  TempPie += dataArray[i]/totalValue; 
 }
 document.body.appendChild(divImage);
}
/**********************************
函数名称:Point
函数说明:定义点坐标类
传入参数:
返回:
**********************************/
function Point(x,y)
{
 this.x=x;
 this.y=y;
 return this;
}
/**********************************
函数名称:Color
函数说明:定义颜色类
传入参数:
返回:
**********************************/
function Color(color1,color2)
{
 this.color1 = color1;
 this.color2 = color2;
 return this;
}
/**********************************
函数名称:getMaxValue
函数说明:获得数组中的最大值
传入参数:
 dataArray:查找最大值的数组
返回:数组中的最大值
**********************************/
function getMaxValue(dataArray)
{
 if(null==dataArray || dataArray.length==0) return 0;
 var maxValue = 0;
 for(var i=0;i<dataArray.length;i++)
 {
  if(dataArray[i]>maxValue)
   maxValue = dataArray[i];
 }
 return maxValue;
}
/**********************************
函数名称:getMinValue
函数说明:获得数组中的最小值
传入参数:
 dataArray:查找最小值的数组
返回:数组中的最小值
**********************************/
function getMinValue(dataArray)
{
 if(null==dataArray || dataArray.length==0) return null;
 var minValue = dataArray[0];
 for(var i=0;i<dataArray.length;i++)
 {
  if(dataArray[i]<minValue)
   minValue = dataArray[i];
 }
 return minValue;
}
/**********************************
函数名称:resetValue
函数说明:对数组中的值按比率缩放
传入参数:
  ratio:比率值
  baseValue:要减去的值
  dataArray:进行缩放数据的数组
返回:缩放后的新数组
**********************************/
function resetValue(ratio,baseValue,dataArray)
{
 if(null==dataArray || dataArray.length==0) return;
 var newArray = new Array();
 for(var i=0;i<dataArray.length;i++)
 {
  newArray[i] = (dataArray[i]-baseValue)*ratio;
 }
 return newArray;
}
/*****************************************
函数名称:getColor
函数说明:获取指定位置的颜色值
传入参数:颜色值索引
返回:颜色变量对象
*****************************************/
function getColor(index)
{
 var color = new Color();
 switch(index)
 {
  case 0:
   {
    color.color1 = "#00ff00";
    color.color2 = "#d1ffd1";
   }
   break;
  case 1:
   {
    color.color1 = "#ff0000";
    color.color2 = "#ffbbbb";
   }
   break;
  case 2:
   {
    color.color1 = "#ff9900";
    color.color2 = "#ffbbbb";
   }
   break;
   return "#ffe3bb";
  case 3:
   {
    color.color1 = "#33cccc";
    color.color2 = "#cff4f3";
   }
   break;
  case 4:
   {
    color.color1 = "#666699";
    color.color2 = "#d9d9e5";
   }
   break;
  case 5:
   {
    color.color1 = "#993300";
    color.color2 = "#ffc7ab";
   }
   break;
  case 6:
   {
    color.color1 = "#99cc00";
    color.color2 = "#ecffb7";
   }
   break;
  case 7:
   {
    color.color1 = "#ff0000";
    color.color2 = "#FF0000";
   }
   break;
  default:
   return "";
 }
 return color;
}
/*****************************************
函数名称:sumArray
函数说明:对数组中的值进行求和
传入参数:进行求和的数组
返回:求和后的值
*****************************************/
function sumArray(dataArray)
{
 var sumValue = 0;
 for(var i=0;i<dataArray.length;i++)
  sumValue = eval(sumValue+dataArray[i]);
 return sumValue;
}
8:57  |  固定链接 | 引用通告 (0) | 记录它 | Javascript研究
2005/11/4
ASP.Net绘制柱状图和曲线图示例
本周对ASP.Net绘制图形做了番学习,学会了如何用C#代码在页面上输出代码图形,但是效果不怎么好。示例如下。
 
public class WebForm1 : System.Web.UI.Page
 {
  private void Page_Load(object sender, System.EventArgs e)
  {
   //This is the interface to outer usage
   int widthValue = 800;
   int heightValue = 500;
   String xTitle,yTitle;
   int offsetX = 20;
   int offsetY = 20;
   //柱状图之间的间距
   int spaceSpan = 15;
   
   xTitle = "Time";
   yTitle = "Sum";

   Bitmap imgBitmap = new Bitmap(widthValue+5*offsetX,heightValue+offsetY*2,PixelFormat.Format32bppPArgb);
   Graphics g = Graphics.FromImage(imgBitmap);
   g.Clear(Color.Snow);
   Pen linePen = new Pen(Color.Black);
   linePen.Width = 2;
   //Draw Title
   Font txtFont = new Font("Courier",10,GraphicsUnit.Point);
   String title= "This is the title to be displayed";
   g.DrawString(title,txtFont,Brushes.Blue,new PointF(imgBitmap.Width/2,0));
   Point original = new Point(offsetX,heightValue+offsetY);
   Point xEndPonit = new Point(widthValue+offsetX ,heightValue+offsetY);
   Point yEndPonit = new Point(offsetX,0);
   //X coordinate
   g.DrawLine(linePen,original,xEndPonit);
   //Y Coordinate
   g.DrawLine(linePen,original,yEndPonit);
   //Draw arrows
   Point leftArrowStart = new Point(offsetX*3/4 ,offsetY/3);
   Point rightArrowEnd = new Point(offsetX*5/4,offsetY/3);
   g.DrawLine(linePen,leftArrowStart,yEndPonit);
   g.DrawLine(linePen,yEndPonit,rightArrowEnd);
   
   Point topArrowStart = new Point(widthValue + offsetX*3/4,heightValue +  offsetY*3/4);
   Point bottomArrowEnd = new Point(widthValue+ offsetX*3/4,heightValue  + offsetY*5/4);
   g.DrawLine(linePen,topArrowStart,xEndPonit);
   g.DrawLine(linePen,xEndPonit,bottomArrowEnd);
   
   
   //Draw X-Title
   g.DrawString(xTitle,txtFont,Brushes.Blue,new PointF(bottomArrowEnd.X -g.MeasureString(xTitle,txtFont).Width,topArrowStart.Y +10));
   StringFormat f = new StringFormat();
   //f.Alignment = StringAlignment.Center;
   //Draw Y-Title
   f.LineAlignment = StringAlignment.Center;
   g.DrawString(yTitle,txtFont,Brushes.Blue,new PointF(offsetX * 5/3,15),f);
   
   //画单个柱状图的代码
   
   //测试数据
   /**
   int[] staticData = new int[]{20,30,80,50,200,120,20,30,80,50,200,120,60,90,140};
   
   int maxValue = MaxValue(staticData);
   
   int ratio = heightValue/maxValue;
   int groupCount = staticData.Length; //柱状图组数
   ResetValue(staticData,ratio);
   
   int rectWidth = (widthValue - (groupCount +1)*spaceSpan )/ groupCount;
   Rectangle rect;
   int startX = offsetX + spaceSpan; //起始坐标点
   for(int i=0;i<staticData.Length;i++)
   {
    rect = new Rectangle(startX,heightValue +offsetY - staticData[i],rectWidth,staticData[i]);
    g.DrawRectangle(Pens.Green,rect);
    g.FillRectangle(Brushes.Green,rect);
    startX = startX + rectWidth + spaceSpan;
   }
   **/
//   Type t = dataList.GetType();
//   if(t.IsArray)
//   {
//   }
   //画分组柱状图代码
   ArrayList dataList = new ArrayList();
   int[] data1= new int[]{20,30,50,100};
   int[] data2 = new int[]{50,60,30,30};
   int[] data3 = new int[]{80,50,60,85};
   int[] data4= new int[]{20,30,90,58};
   int[] data5 = new int[]{50,60,30,30};
   int[] data6 = new int[]{80,50,60,85};
   int[] data7= new int[]{20,30,90,58};
   dataList.Add(data1);
   dataList.Add(data2);
   dataList.Add(data3);
   dataList.Add(data4);
   dataList.Add(data5);
   dataList.Add(data6);
   dataList.Add(data7);
   int maxValue = MaxValue(dataList);
   int ratio = heightValue/maxValue;
   int groupCount = dataList.Count; //柱状图组数
   ResetValue(dataList,ratio);
   
   //根据比率画坐标
   //Draw X-Grids, The height value is divided into 10 parts
   int heightStep = heightValue/10;
   Point point1,point2;
   for(int i=1;i<=10;i++)
   {
    point1 = new Point(offsetX*3/4,offsetY+heightValue - heightStep*i);
    point2 = new Point(offsetX,point1.Y);
    g.DrawLine(Pens.Black,point1,point2);
    String text = maxValue/10*i+"";
    g.DrawString(text,txtFont,Brushes.Blue,new PointF(-2,point1.Y));
   }
   //画坐标结束
   int rectWidth = (widthValue - (groupCount +1)*spaceSpan )/ groupCount;
   int innerGroupCount = GetInnerGroupCount(dataList);
   int innerWidth = rectWidth / innerGroupCount;
   Rectangle rect;
   int startX = offsetX + spaceSpan; //起始坐标点
   for(int i=0;i<dataList.Count;i++)
   {
    int[] staticData = (int[])dataList[i];
    for(int j=0;j<staticData.Length;j++)
    {
     rect = new Rectangle(startX,heightValue +offsetY - staticData[j],innerWidth,staticData[j]);
     g.DrawRectangle(GetPenColor(j),rect);
     g.FillRectangle(GetBrushColor(j),rect);
     startX = startX + innerWidth;
    }
    startX = startX + spaceSpan;
   }
   //画曲线
   Point pnt1 = new Point(200+offsetX,heightValue+offsetY-300);
   Point pnt2 = new Point(300+offsetX,heightValue+offsetY-500);
   Point pnt3 = new Point(400+offsetX,heightValue+offsetY-300);
   Point pnt4 = new Point(600+offsetX,heightValue+offsetY-600);
   g.DrawCurve(Pens.Purple,new Point[]{pnt1,pnt2,pnt3,pnt4});
   //画饼图
   g.DrawPie ( Pens.Red , 50 , 50 , 150 , 150 , 0 , 30 ) ;
   imgBitmap.Save(Response.OutputStream,ImageFormat.Gif);
  }
 
代码中涉及到的函数如下:
private int MaxValue(int[] data)
  {
   int maxValue = 0;
   for(int i=0;i<data.Length;i++)
   {
    if(data[i]>maxValue)
     maxValue = data[i];
   }
   return maxValue;
  }
  private int MaxValue(ArrayList dataList)
  {
   int maxValue = 0;
   for(int i=0;i<dataList.Count;i++)
   {
    int newMaxValue = MaxValue((int[])dataList[i]);
    if( newMaxValue>maxValue)
     maxValue = newMaxValue;
   }
   return maxValue;
  }
  private void ResetValue(int[] data,int ratio)
  {
   for(int i=0;i<data.Length;i++)
    data[i] *= ratio;
  }
  private void ResetValue(ArrayList dataList,int ratio)
  {
   for(int i=0;i<dataList.Count;i++)
   {
    ResetValue((int[])dataList[i],ratio);
   }
  }
  private int GetInnerGroupCount(ArrayList dataList)
  {
   int groupCount = 0;
   for(int i=0;i<dataList.Count;i++)
   {
    int count = ((int[])dataList[i]).Length;
    if(count>groupCount)
     groupCount = count;
   }
   return groupCount;
  }
  private Pen GetPenColor(int index)
  {
   Pen linePen = new Pen(Color.Black);
   linePen.Width = 1;
   linePen.CompoundArray = new float[]{0.0F,0.2F};
   switch(index)
   {
    case 0:
     linePen.Color = Color.Gray;
     break;
    case 1:
     linePen.Color = Color.Green;
     break;
    case 2:
      linePen.Color = Color.Blue;
     break;
    case 3:
     linePen.Color = Color.Purple;
     break;
   }
   return linePen;
  }
  private Brush GetBrushColor(int index)
  {
   switch(index)
   {
    case 0:
     return Brushes.Gray;
    case 1:
     return Brushes.Green;
    case 2:
     return Brushes.Blue;
    case 3:
     return Brushes.Purple;
   }
   return Brushes.Red;
  }
------------------------------------------------------------
运行结果见附图。
12:53  |  固定链接 | 引用通告 (0) | 记录它 | Javascript研究
2005/8/27
Persia & Gregorian Convert 公历和伊朗历法转换(Calendar convertor between Persian and Gregorian)

/**********************************************************
函数名称:calendarToPersian
函数说明:公历转换为波斯历
传入参数:datetimeValue:需要进行转换的公历日期值
返回:转换后的日历值
***********************************************************/
function calendarToPersian(datetimeValue)
{
 var yearValue = datetimeValue.substring(0,4);//Year value
 var monthValue = datetimeValue.substring(5,7)*1;//Month value
 var dayValue =datetimeValue.substring(8,10)*1;//Day value
 monthValue -= 1;
 var persianDate = getPersianDay(yearValue,monthValue,dayValue);
 persianDate.month += 1;
 persianDate.month = persianDate.month.toString().length==1?"0"+persianDate.month:persianDate.month;
 persianDate.day = persianDate.day.toString().length==1?"0"+persianDate.day:persianDate.day;
 return persianDate.year+"-"+persianDate.month+"-"+persianDate.day
}

/**********************************************************
函数名称:persianToGregorian
函数说明:转换波斯历为公历
传入参数:datetimeValue:需要进行转换的波丝历日期值
返回:转换后的日历值
***********************************************************/
function persianToGregorian(datetimeValue)
{
 var persiaYear = datetimeValue.substring(0,4)*1;//Year value
 var persiaMonth = datetimeValue.substring(5,7)*1;//Month value
 var persiaDay =datetimeValue.substring(8,10)*1;//Day value
 persiaMonth -= 1;
 var julianDay = setJulianDay(pj(persiaYear > 0 ? persiaYear: persiaYear + 1, persiaMonth, persiaDay));
 julianDay.month = julianDay.month.toString().length==1?"0"+julianDay.month:julianDay.month;
 julianDay.day = julianDay.day.toString().length==1?"0"+julianDay.day:julianDay.day;
 return julianDay.year+"-"+julianDay.month+"-"+julianDay.day;
}

/**********************************************************
函数名称:getPersianDay
函数说明:根据输入的日期获得Persia日期值
传入参数:year,month,day
返回:转换后的日历值
***********************************************************/
function getPersianDay(year,month,day)
{
 var julianDay = getJulianDay(year,month,day);
 var r = jp(julianDay);
 var y1 = y(r);
 var m1 = m(r);
 var d1 = d(r);
 y1 = y1 > 0?y1:y1-1;
 var persiaDate = new Object();
 persiaDate.year  = y1;
 persiaDate.month = m1;
 persiaDate.day = d1;
 return persiaDate;
}
/**********************************************************
函数名称:getJulianDay
函数说明:根据输入的日期获得公历日期值
传入参数:year,month,day
返回:转换后的日历值
***********************************************************/
function getJulianDay(year,month,day)
{
 var current = new Date();
 var hour = current.getHours();
 var min = current.getMinutes();
 var sec = current.getSeconds();
 return div(new Date(year,month,day,8,1,1) - JULIAN_EPOCH_MILLIS, ONE_DAY_MILLIS);
}
/**********************************************************
函数名称:setJulianDay
函数说明:根据输入的日期获得公历日期值
传入参数:julianDay
返回:转换后的日历值
***********************************************************/
function setJulianDay(julianDay)
{
 var current = new Date();
 var year = current.getYear();
 var month = current.getMonth();
 var day = current.getDay();
 
 var datetimevalue = JULIAN_EPOCH_MILLIS + julianDay * ONE_DAY_MILLIS + mod(new Date(year,month,day,8,1,1) - JULIAN_EPOCH_MILLIS, ONE_DAY_MILLIS);
 var current = new Date(datetimevalue);
 var julianDate = new Object();
 julianDate.year  = current.getYear();
 julianDate.month = eval(current.getMonth()+1);
 julianDate.day = current.getDate();
 return julianDate;
}
/**********************************************************
函数名称:jp
函数说明:公历转换为波斯历
传入参数:julianDay
返回:转换后的日历值
***********************************************************/
function jp(j)
{
 var a = j - pj(475, 0, 1);
 var b = div(a, 1029983);
 var c = mod(a, 1029983);
 var d = c != 1029982? div(2816 * c + 1031337, 1028522): 2820;
 var year = 474 + 2820 * b + d;
 var f = (1 + j) - pj(year, 0, 1);
 var month = f > 186? Math.ceil((f - 6) / 30) - 1: Math.ceil(f / 31) - 1;
 var day = j - (pj(year, month, 1) - 1);
 return (year << 16) | (month << 8) | day;
}
/**********************************************************
函数名称:pj
函数说明:波斯历转换为公历
传入参数:y,m,d
返回:转换后的日历值
***********************************************************/
function pj(y, m, d)
{
 var a = y - 474;
 var b = mod(a, 2820) + 474;
 return (EPOCH - 1) + 1029983 * div(a, 2820) + 365 * (b - 1) + div(682 * b - 110, 2816) + (m > 6? 30 * m + 6: 31 * m) + d;
}

function div(a,b)
{
 return Math.floor(a / b);
}

function mod(a,b)
{
 return (a - b * Math.floor(a / b));
}

function y(r)
{
 return r>>16;
}

function m(r)
{
 return (r & 0xff00) >> 8;
}

function d(r)
{
 return (r & 0xff);
}

-------------------------------------------------

返回日期值时一定要注意:getYear(),getMonth(),getDate(),而不是使用getDay()!

说明:将公历转换为波斯历(Persian Calendar)时,调用方法calendarToPersian();

将波斯历转换为公历时,调用方法persianToGregorian(),传入的日期格式为:YYYY-MM-DD,如:

calendarToPersian("2005-08-30");

persianToGregorian("1384-06-08");

PS:源码作者保留算法拥有的权利。本人只对原Java代码翻译为Javascript表达。

14:07  |  固定链接 | 引用通告 (0) | 记录它 | Javascript研究
2005/7/18
Linux学习
 设置telnet-server的启动运行
  telnet server不作为独立的服务器程序运行,而是受xinetd程序的控制,启动配置文件为/etc/xinetd.d/telnet,默认xinetd程序并不启动该服务,可在chkconfig --list看出telnet是关闭的,/etc/xinetd.d/telnet中disable=yes可通过下面的方式启动telnet server:
 1) chkconfig telnet on  //该命令修改了/etc/xinetd.d/telnet的配置,设置disable=no
 2) service xinetd restart
 再次chkconfig --list看到telnet server已经启动。
 
------------------------------------------------------------
修改Linux 的IP地址:
netconfig
停止网卡:ifdown eth0
启动网卡:ifup eth0
查看本机IP地址:ifconfig
-------------------------------------------------------------
native2ascii -encoding gb2312 aaa.properties bb.properties ----将GB2312格式的资源文件转换为UTF8格式
native2ascii -reverse -encoding gb2312 bb.properties aaa.properties --将UTF8格式的资源文件转换为中文格式

 

----------------------

Linux 中加载NTFS文件系统时需要下载的RPM包位置:
http://rpmseek.com/rpm-pl/kernel-ntfs.html?hl=com&cx=0%3A-%3A0%3A0%3A0%3A0%3A0&qDnStr=0&qRtStr=0&qArStr=3

16:51  |  固定链接 | 引用通告 (0) | 记录它 | Linux学习
2005/7/14
炼狱:window.createPopup()弹出提示tips
CCBS 系统增加了新的需求,给界面上的Text文本输入框和Select下拉框增加信息提示。
对于Text输入框来说,实现起来并不难:重载Text文本框的onmouseover事件,然后显示出Text文本框的title也就可以了。
但是,对于Select控件来说就远远没有这么简单了。首先Select本身没有Title属性!无疑增加了实现的难度。
在网上找了点资料后,发现window.createPopup()函数可以实现弹出式的tips,而且微软的技术支持网站也有这方面的例子(参见:http://msdn.microsoft.com/workshop/samples/author/dhtml/popup/usingpopup.htm)。但是实现起来并不是那么一帆风顺的事情。
首先,window.createPopup()生成的窗口在显示的时候要手动指定该窗口的位置(x,y坐标),窗口的宽度和高度。而显示的内容是变化的,显示的字符串有长有短,窗口的长度和宽度也要跟着变化,如何实现呢?
其次,windows网页上的title属性在显示提示信息的时候是永远不会换行的,哪怕你显示的信息超过屏幕的显示范围它也不会顾忌到你的感受。windows标准就是我们的标准,我们也只能仿效了。
上面的两个问题着实让我困惑了一阵子,应该说是一个下午吧。不过最后问题还是得到解决了,虽然过程颇有些周折。
首先解决的是弹出窗口的指定位置,宽度和高度问题。窗口的位置就是响应鼠标事件的位置,但是该位置一定要区分清楚,鼠标如下几个位置的参数:clientX,clientY;offsetX,offsetY,screenX,screenY,x,y等。(具体每个位置的意义有单独的文章来解释)在这里应该是相对于响应控件的位置,使用的是offsetX,offsetY值。
要控制createPopuo()生成的窗口的宽度和高度,必须使用一个比较“土”的方法:首先调用oPopup.show(0,0,width,height)方法,马上获得该窗体的scrollWidth,scrollHeight,然后对该窗体隐藏:oPopup.hide()。获得具体的宽度和高度之后,再在具体的位置上显示真正的提示信息:
oPopup.show(x,y,scrollWidth,scrollHeight)。也就是说:在真正显示tips之前要调用一次显示方法获得实际的宽度和高度!这是解决问题的重点!!!
让显示的信息不换行的问题解决过程说难也不难,重要的是要能够想到该方法:使用table中的td不允许换行的属性:nowrap,那么包含在td中的内容就会一直显示出来,永远都不会换行了!!!
代码的范例如下:
 
var winPopup = window.createPopup(); //Create the window to popup
var winstr="<table style=\" border: 1 solid  #FFA6CA\" border=\"0\" width=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\"  background=\"\" >";
 winstr+="<tr><td align=\"center\"><table width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
 winstr+="<tr><td nowrap id=\"tdMsg\" valign=\"center\" style=\"font-size:12px; color: red; face: Tahoma\"></td></tr></table></td></tr></table>";
winPopup.document.body.innerHTML = winstr;
var eventElement = null;
var xPos = 0;
var yPos = 0;
var timer = null;
/*************************************************************************
 Function Name:showPopupHelp
 Description:Popup a window that shows the content of text or select
 Input Parameter:None
 Output :None
 Return:None
 ***********************************************************************/
function showPopupHelp(helpMsg)
{
 initPopupWindow(helpMsg);
 eventElement = event.srcElement;
 xPos= window.event.offsetX;
 yPos= window.event.offsetY;
 timer = setTimeout("showPopupWindow()",1000);
}
/*************************************************************************
 Function Name:hidePopupHelp
 Description:Invisible the popup window
 Input Parameter:None
 Output :None
 Return:None
 ***********************************************************************/
function hidePopupHelp()
{
 clearTimeout(timer);
 winPopup.hide();
}
/*************************************************************************
 Function Name:initPopupWindow
 Description:Initilize the popup window,draw the frame
 Input Parameter:String to show
 Output :None
 Return:None
 ***********************************************************************/
function initPopupWindow(msgstr)
{
 winPopup.document.all('tdMsg').innerText = msgstr;
}
/*************************************************************************
 Function Name:showPopupWindow
 Description:Visible the popup window
 Input Parameter:None
 Output :None
 Return:None
 ***********************************************************************/
function showPopupWindow()
{
 winPopup.show(0,0,10,10);
 var h = winPopup.document.body.scrollHeight;
 var w = winPopup.document.body.scrollWidth;
 winPopup.hide();
 //var w = eventElement.offsetWidth;
 //var h = winPopup.document.body.scrollHeight;
 //var x = eventElement.style.left;
 //var y = eventElement.style.top + eventElement.offsetHeight;
 var x = xPos + 3;
 var y = yPos + 3;
 winPopup.show(x,y,w,h,eventElement);
 delete eventElement;
}
18:38  |  固定链接 | 引用通告 (0) | 记录它 | Javascript研究
2005/7/6
经典网页代码

1.使网页不能被“另存为”
<body>里面加下面这段:
<noscript>
<iframe src="*.htm">
</iframe>
</noscript>

2.彻底屏蔽鼠标右键

<body>里面加上下面这段:
<script language="javascript">
<!--

if (window.Event)
document.captureEvents(Event.MOUSEUP);

function nocontextmenu()
{
event.cancelBubble = true
event.returnvalue = false;

return false;
}

function norightclick(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true
event.returnvalue = false;
return false;
}

}

document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
</script>


3.超连接单元格变色

A:visited{TEXT-DECORATION: none}
A:active{TEXT-DECORATION: none}
A:hover{TEXT-DECORATION: underline overline}
A:link{text-decoration: none;}
表格单元,在单元格的<td>标记里加上:onMouseOut="this.style.backgroundColor='' "onMouseOver=this.style.backgroundColor='#E0E2ED'就可以了
onMouseOut="this.style.border='0px solid #cccccc';this.style.backgroundColor='' "onMouseOver="this.style.border='1px solid #cccccc';this.style.backgroundColor='#E0E2ED'"

4.细表格边框

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="158" height="68">
<tr>
<td width="158" height="68"> </td>
</tr>
</table>

5.网页全屏显示

把如下代码加入<body>区域中
<SCRIPT LANGUAGE="javascript">
<!-- Begin
if (this.name!='fullscreen'){
window.open(location.href,'fullscreen','fullscreen,scrollbars')
}
// End -->
</script>
<a href="javascript :window.close(self)">返回正常效果显示</a>


6.表格虚线

使用CSS,新建一个Style,选择“Redefine HTML Tag”,在下拉菜单中选择“td”,在弹出对话框中的“Category”里选择“Border”,将Top、Left、Right、Bottom都设成1px,颜色设成你想要的边框的颜色。然后在“Style”下拉框里选择“Dashed”,点“OK”。这样所有的表格都变成虚线的了。
或:
<table><td style="border:dashed 1px #00000">test</td></table>


7.连接全屏

<a href="#" onClick="window.open(URL,'','fullscreen=1')">Link</a>
通过连接可以打开一个全屏窗口

8.DW层的定位

用菜单插入层,不要用面板的。
主要就是不要设定层的left和right属性


9.css阴影滤镜

<div style="width:754;height:13;color:black;filter:dropshadow(color=white,offx=1,offy=1,positive=2);">  首页 关于本站 设计作品 </div>

<div style="width:75;height:1;color:black;filter:dropshadow(color=#cccccc,offx=1,offy=1,positive=2);" align="center"><font color="#414992"><a href="index.htm">首页</a></font></div>


10.关闭窗口

<a href="javascript :closewin();">关闭本页</a>
<script language=javascript>
function closewin() {window.close(); return;}
</script>


1.图层的准确定位

在单元格里Insert/Layer,插入一个图层A(通过菜单插入的图层是相对定位),他的位置是跟着参照物改变的。接着图层A中插入一个图层B。这时你可移动图层B到任何位置。这时图层B的位置是绝对的,但这个绝对植的起点不是浏览器的左上角。而是图层A。


1.自动连接到另一页

<meta http-equiv="refresh" content="5;URL=index.htm">


2.虚线表格

<title>虚线</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.unnamed1 { border: #000000; border-style: dotted; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
-->
</style>
</head>

<body bgcolor="#FFFFFF" text="#000000">

<table width="289" border="0" cellpadding="0" cellspacing="0" class="unnamed1">
<tr>
<td width="289" height="220"></td>
</tr>
</table>
</body>


3.不同分辨率返回不同页面

<script language="javascript">
<!-- Begin
if ((screen.width == 640) && (screen.height == 480)){
self.location.href='640*480.htm'
}
else if ((screen.width == 800) && (screen.height == 600)){
self.location.href='800*600.htm'
}
else if ((screen.width == 1024) && (screen.height == 768)){
self.location.href='1024*768.htm'
}
else {self.location.href='else.htm'
}
// End -->
</script>


4.显示日期

<script language="javascript"><!--
today=new Date();
var week; var date;
if(today.getDay()==0) week="星期日"
if(today.getDay()==1) week="星期一"
if(today.getDay()==2) week="星期二"
if(today.getDay()==3) week="星期三"
if(today.getDay()==4) week="星期四"
if(today.getDay()==5) week="星期五"
if(today.getDay()==6) week="星期六"
date=(today.getYear())+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日"+" "
document.write("<span style='font-size: 9pt;'>"+date+week+"</span>");
// -->
</script>

5.表格一行多个
在table里加style="float:left"

27> 如何自动加入网页更改后的日期?
只需要在源文件<body></body>之间添加如下代码即可。

< Script Language=“JavaScript”><!--
document.write(“Last Updated:”+document.lastModified);
-->< /Script>

鼠标感应渐显图片代码
<script language="javascript1.2">
function makevisible(cur,which){
if (which==0)
cur.filters.alpha.opacity=100
else
cur.filters.alpha.opacity=20
}
</script>
<img src="tp1.gif" style="filter:alpha(opacity=20)" onMouseOver="makevisible(this,0)" onMouseOut="makevisible(this,1)">

(((<!--tp1.gif为图片源-->
<!--opacity数值可自定-->

cur.filters.alpha.opacity=100


cur.filters.alpha.opacity=20

两个数值分别用来控制图片在两种状态下的透明度。)))

插入单根虚线水平线
<hr style="border:dashed #0099cc; width:1px; height:300px">
<hr size="1" noshade style="border:none #cc9900; width:100%; height:1">
<hr size="1" noshade style="color:#ffccee; width:100%; height:1">

插入单根虚线水平线2
<p size=1 style="border:1px dotted #001403;">

如果要使Flash动画背景透明,我们需要在Dreamweaver中对动画进行设置:

  1.在DW中插入一个Flash动画,在对象属性栏中点击参数(Parameters)按钮;
  2、在参数设定对话框中,点击加号新建一参数,左边参数项填入Wmode,右边参数值填入Transparent;

  这样,用浏览器打开保存好的页面时,你就会发现Flash动画的背景已经变为透明。

  反映到HTML代码上,即是在插入Flash的<OBJECT>标签中插入以下代码:<param name=″Wmode″ value=″transparent″>

按纽,输入框等更改背景和线框颜色
在<input 后加入以下代码
class="purchase(为文字定义颜色的css名)" style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid; BACKGROUND-COLOR: #993300"

表单里的文本框有提示文字,鼠标移上去就消失
在<input name="textfield1" 后加入onFocus="this.value=''"

改变文字,单元格所引用的css样式
<td onMouseOver="this.className='要变化的css名不要点号';"

半透明图片,鼠标移上去就完全显现
<img class="low" onMouseOver="this.className='high'"; onMouseOut="this.className='low'">
low为css设置好的半透明,high为css中设置好的完全显示

改变图片/按纽/文字的其他属性---以图片为例
<img src="img1" onMouseOver="this.src='img2'" onMouseOut="this.src='img1'">
如果改变图片的大小就将this.src改成this.width或者this.height

插入一个左上角带标题的表格
<fieldset style="width:220" align="center">
<legend>这里是表格的标题</legend>
这里添加表格中的内容
</fieldset>

表格可以带滚动条
在<td>与</td>中加入<div style="overflow:auto;height:160;">
这里输入文段的内容。
</div>

非常酷的黑色立体滚动条
<STYLE type="text/css">
<!--BODY {
scrollbar-face-color:#424542;
scrollbar-arrow-color:#CECFCE;
scrollbar-highlight-color:#636563;
scrollbar-3dlight-color:#000000;
scrollbar-shadow-color:#424542;
scrollbar-darkshadow-color:#000000;
scrollbar-track-color:#101010;
}--></STYLE>
放在<head>与</head>之间

进入页面需要密码。三次错误则退出[放在<body>与</body>之间]

<SCRIPT LANGUAGE="JavaScript">
function password() {
var testV = 1;
var pass1 = prompt('桔子私人资料请输入密码','');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1 == "loveorange") {
alert('密码正确!');
break;
}
testV+=1;
var pass1 =
prompt('密码错误!请勿尝试点取消退出:');
}
if (pass1!="password" & testV ==3)
history.go(-1);
return " ";
}
document.write(password());
</SCRIPT>

发送表单至邮箱(为html格式不需要启动outlook)
<form action=http://gz.ce.net.cn/sendmail/sendmail.asp method=post
name=submitform>
<input name=sendemail type=hidden
value=sales@hotel-canton.net>
<input name=tHtml type=hidden>
后面加上放置表单的表格(里面可以添加多个表单元素)
发送按钮的代码必须为 <input id=button1 name=button1 onClick="submitform.tHtml.value=submitform.innerHTML; submitform.submit();" type=submit value=发送>将邮件地址改为需要即可

个性化鼠标指针
<A style="cursor: url('/imagesnew/software/030829/stopwtch.ani')" href="http://homepage.yesky.com/";>个性指针</a>

鼠标指向单元格变色
< td onmouseout="this.style.backgroundColor='#ffffff'" onmouseover="this.style.backgroundColor='#FFcccc'"> </td>

在输入框中输入文字每按一个键背景就变色一次
<td><input onKeyUp="this.style.backgroundColor='#b4f3c7'" onKeyDown="this.style.backgroundColor='#cc3366'" type="text" name="textfield"></td>

表格阴影
新建一个滤镜css。然后将css里的相应位置替换成
filter:progid:DXImageTransform.Microsoft.Shadow
(Color=#333333,Direction=120,strength=5)">;
把这个css给表格使用。注意一定要给表格使用一种背景色

同一个页面内不同的文字有不同的链接色彩
新建css选择器 更改a:link 为 a.k1:link
a:visited 为 a.k1:visited
a:hover 为 a.k1:hover
而后将要链接的文字应用k1的css就可以了

屏蔽滚动条
<body scroll="no" style="overflow-y:hidden">

让浏览器窗口永远都不出现滚动条<body
style="overflow:hidden">

点击文字打开真正全屏幕窗口

在<head>与</head>之间插入以下代码
<SCRIPT language=JavaScript type=text/JavaScript>
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</SCRIPT>
在文字的链接框里输入
javascript :MM_openBrWindow('enterflash.htm','','toolbar=no,fullscreen=yes,location=no,status=no,menubar=no,scrollbars=no,resizable=no')
注: enterflash.htm为要打开的全屏幕窗口的网页文件地址
改 enterflash.htm文件里的<body>为<body style="overflow:hidden">
如果是设置成不需要点文字就可以的话就将启动全屏幕页面的<body>改为<body onload=MM_openBrWindow('enterflash.htm','','toolbar=no,fullscreen=yes,location=no,status=no,menubar=no,scrollbars=no,resizable=no')


posted on 2007-02-06 12:36  mbskys  阅读(1275)  评论(0)    收藏  举报