100分在线等,求JS柱状图 带负轴的!! http://www.itlearner.com/code/vml/index.html用 vml画比较好 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你搜索一下下面的代码,把它们注释掉,看看行不行。我这里没法测试。 if total(i,1)<0 then sz= -total(i,1) else sz= total(i,1) end if 用JS画图,好象兼容性是个大问题,IE下的VML在FF下用不上,而FF里也有其特有画图工具! 这是我从一个软件里面提取出来的,仅供参考,代码比较多,不过肯定有负轴,你直接下载吧http://files.cnblogs.com/alexis/about_blank%5b1%5d.rar google 有API 。直接带入参数调用就好了http://code.google.com/intl/zh-CN/apis/charttools/index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head> <title>无标题页</title> <style type="text/css"> DIV {width:40px;} DIV.PLUSDIV{background-color:blue; } DIV.MINUSDIV{background-color:red;} </style> <script type="text/javascript"> function chartData(name,value) { this.name=name; this.value=value; } var datas = new Array(); datas.push(new chartData("1月",2000.00)); datas.push(new chartData("2月",3000.00)); datas.push(new chartData("3月",1000.00)); datas.push(new chartData("4月",-1500.00)); datas.push(new chartData("5月",6000.00)); datas.push(new chartData("6月",4000.00)); function getMax() { var max = 0.0; for(var i=0;i<datas.length;i++) { if(datas[i].value>max) max = datas[i].value; } return max; } function getMin() { var min = 0.0; for(var i=0;i<datas.length;i++) { if(datas[i].value<min) min = datas[i].value; } return min; } function drawChart() { var max = getMax(); var min = getMin(); var scope= max-min; if(max>0&&scope<max) scope = max; else if(max<0) scope=-1*min; var str = "<TABLE>"; var plusValues = "<TR>"; var minusValues = "<TR>"; for(var i=0;i<datas.length;i++) { if(datas[i].value>0) { divHeight=Math.ceil(300*(datas[i].value/scope)); plusValues +="<TD valign=bottom style='border-bottom:solid black 2px;'><DIV CLASS=PLUSDIV style='height:"+divHeight+"px'>"; minusValues+="<TD >"; }else { divHeight=Math.ceil(-300*(datas[i].value/scope)); minusValues +="<TD valign=top><DIV CLASS=MINUSDIV style='height:"+divHeight+"px'>"; plusValues+="<TD style='border-bottom:solid black 2px;'>"; } } str += plusValues+minusValues+"</TABLE>"; document.getElementById("CHARTTD").innerHTML = str; } </SCRIPT></head><body><TABLE border=1> <TR><TD>2010年度销售记录 <TR><TD id=CHARTTD> </TABLE> </body></html><SCRIPT> drawChart();</SCRIPT> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> New Document </TITLE><SCRIPT LANGUAGE="JavaScript"><!-- var force_color = new Array();var bg_color = new Array();force_color[0]="#d1ffd1";force_color[1]="#ffbbbb";force_color[2]="#ffe3bb";force_color[3]="#cff4f3";force_color[4]="#d9d9e5";force_color[5]="#ffc7ab";force_color[6]="#ecffb7";bg_color[0]="#00ff00";bg_color[1]="#ff0000";bg_color[2]="#ff9900";bg_color[3]="#33cccc";bg_color[4]="#666699";bg_color[5]="#993300";bg_color[6]="#99cc00";line_color="#69f";var left_width=30;var bottom_height=20;function histogram(ar,space,width,height){//柱阴影厚度var thickness = space/2;if (thickness<1)thickness =0;thickness = space;//数据长度var length = ar.length;var iMax=0,iWidth=0,iHeight=0,tMax=0;//数据最大值var i,j,obj,tmp;var index=-1;//验证if (length==0) return;for(i=0;i<length;i++){obj = ar[i].split("|");for(j=0;j<obj.length;j++){tmp = parseInt(obj[j]);if(tmp>iMax) iMax =tmp;}}tmp = iMax+'';j = tmp.length;if(iMax>9){i= parseInt((iMax %100)/10);if(i>4)tMax =(parseInt(iMax/Math.pow(10,(j-1)))+1)*Math.pow(10,j-1);elsetMax =(parseInt(iMax/Math.pow(10,(j-1)))+0.5)*Math.pow(10,j-1);}else{if(iMax>4)tMax = 10;elsetMax= 5;}document.write('<table width="'+width+'" height="'+height+'" border="0" cellpadding="0" cellspacing="0"><tr>');document.write('<td width="'+left_width+'" align="right" valign="bottom" height="'+(height-bottom_height)+'"><v:line style="position:absolute;left:0px;top:0px;right:0px;" alt="" to="'+left_width+'px,-'+(height-bottom_height)+'px" from="'+left_width+'px,0px"/>');//画分隔线iMax = 5;tmp = ((height-bottom_height)/iMax);i=1;if(tmp>40){iMax=10;tmp = ((height-bottom_height)/iMax);}while(tmp>40){iMax=10*(i++);tmp = ((height-bottom_height)/iMax);}if(i>1) {iMax-=10;tmp = ((height-bottom_height)/iMax);}document.write("<table width='100%' border='0' cellpadding='0' cellspacing='0' >");for(i=iMax;i>=1;i--){document.write("<tr><td height='"+tmp+"' align='center' style='border-top:1px solid #000000;' valign='top'>"+(tMax/iMax*i)+"</td></tr>");}document.write("</table><v:line to='0px,-"+(height-bottom_height)+"px'/> ");document.write('</td><td height="'+(height-bottom_height)+'" valign="bottom">');document.write("<v:line strokecolor='"+line_color+"' to='15px,"+(tmp*(iMax)-15)+"px' from='15px,0px' />");for(i=0;i<iMax;i++){document.write("<v:line strokecolor='"+line_color+"' from='0px,"+(tmp*(i+1))+"' to='15px,"+(tmp*(i+1)-15)+"px' />");document.write("<v:line strokecolor='"+line_color+"' to='15px,"+(tmp*(i+1)-15)+"' from='"+(width-left_width)+"px,"+(tmp*(i+1)-15)+"' />");}document.write('<v:rect alt="" style="position:absolute;width:'+(width-left_width)+';height:'+(height-bottom_height)+';z-index:-9" fillcolor="#9cf" stroked="f"><v:fill rotate="t" angle="-45" focus="100%" type="gradient"/></v:rect>');document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="'+left_width/2+'"></td>');//柱状图tmp = (width-2*left_width)/length;index = (height-bottom_height)/tMax;for(i=0;i<length;i++){obj = ar[i].split("|");document.write("<td valign='bottom' width='"+tmp+"' align='center' height='"+(height-bottom_height)+"'>");document.write('<v:group ID="group1" style="position:relative;WIDTH:'+tmp+'px;HEIGHT:'+(height-bottom_height)+'px;" coordsize = "'+tmp*10+','+(height-bottom_height)*10+'">');document.write("<v:textbox style='position:absolute;left:0;top:-15;' inset='0px,0px,0px,0px' ><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='center'>"+formatNumber(obj[1],2)+"</td></tr></table></v:textbox>");document.write('<v:rect style="position:relative;width:'+(tmp-space/2-15)*10+';height:'+index*parseInt(obj[1])*10+';" fillcolor="'+bg_color[i%bg_color.length]+'">');//if(index*parseInt(obj[1])>10)document.write("<v:fill style='position:relative;' color2='"+force_color[i%force_color.length]+"' rotate='t' type='gradient'/>");document.write("<o:extrusion v:ext='view' style='position:relative;' backdepth='"+thickness+"px' color='"+bg_color[i%bg_color.length]+"' on='t'/>");document.write('</v:rect>');document.write('</v:group>');document.write("</td>");}document.write('</tr></table>');//document.write('</v:rect>');document.write('</td></tr><tr><td height="'+bottom_height+'"></td>');document.write('<td valign="bottom" height="'+bottom_height+'" width="'+(width-left_width)+'" style="border-top:1px solid #000000" >');document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="'+left_width/2+'"></td>');for(i=0;i<length;i++){obj = ar[i].split("|");document.write("<td width='"+tmp+"' align='center'>"+obj[0]+"</td>");}document.write('</td></tr></table>');document.write('</td></tr></table>');}function formatNumber(obj,length){if(isNaN(obj)) return obj;var tmp=obj+'';var index = tmp.indexOf(".");if(index!=-1){return obj.substring(0,index+3);}elsereturn obj;}//--></SCRIPT><style type="text/css">v\:* { behavior: url(#default#VML) }o\:* { behavior: url(#default#VML) }.shape { behavior: url(#default#VML) }body{font-size:12px;}td{font-size:12px;}</style></HEAD><BODY><table width="500" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td height="30" align="center" style="font-size:16px;font-weight:bold;color:#fc3a00;">发帖量统计</td></tr> <tr> <td ><script language="javascript">var ar,space,width=500,height=400;ar = new Array();ar[0]="攒机买机|245"; ar[1]="硬件讨论|120";ar[2]="笔记本专区|852";ar[3]="数码产品|424";ar[4]="操作系统|412";ar[5]="软件下载|751";ar[6]="影视下载|123";space=20;histogram(ar,space,width,height);</script></td> </tr></table></BODY></HTML> javaScript获取"芬兰"时区问题 一个页面的 值传到另一个页面 js中如何把2009年2月28日 12:23转换成2009-02-28 12:23的形式?? *********************************字符串和数字 没有原型链????? 如何对 JS脚本加密,保护版权 引入jquery报NetworkError: 400 Bad Request 这个程序有什么问题啊 如何将IE的边框全部去掉??? 请大家帮我看看这段代码,我实在是看不明白. 怎样动态添加listbox的一个子项???? 我把复选框变成了单选的功能,还差个区别,那位指点下。 内嵌样式
if total(i,1)<0 then
sz= -total(i,1)
else
sz= total(i,1)
end if
http://files.cnblogs.com/alexis/about_blank%5b1%5d.rar
直接带入参数调用就好了
http://code.google.com/intl/zh-CN/apis/charttools/index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<style type="text/css">
DIV {width:40px;}
DIV.PLUSDIV{background-color:blue; }
DIV.MINUSDIV{background-color:red;}
</style>
<script type="text/javascript">
function chartData(name,value)
{
this.name=name;
this.value=value;
}
var datas = new Array();
datas.push(new chartData("1月",2000.00));
datas.push(new chartData("2月",3000.00));
datas.push(new chartData("3月",1000.00));
datas.push(new chartData("4月",-1500.00));
datas.push(new chartData("5月",6000.00));
datas.push(new chartData("6月",4000.00));
function getMax()
{
var max = 0.0;
for(var i=0;i<datas.length;i++)
{
if(datas[i].value>max)
max = datas[i].value;
}
return max;
}
function getMin()
{
var min = 0.0;
for(var i=0;i<datas.length;i++)
{
if(datas[i].value<min)
min = datas[i].value;
}
return min;
}
function drawChart()
{
var max = getMax();
var min = getMin();
var scope= max-min;
if(max>0&&scope<max)
scope = max;
else if(max<0)
scope=-1*min;
var str = "<TABLE>";
var plusValues = "<TR>";
var minusValues = "<TR>";
for(var i=0;i<datas.length;i++)
{
if(datas[i].value>0)
{
divHeight=Math.ceil(300*(datas[i].value/scope));
plusValues +="<TD valign=bottom style='border-bottom:solid black 2px;'><DIV CLASS=PLUSDIV style='height:"+divHeight+"px'>";
minusValues+="<TD >";
}else
{
divHeight=Math.ceil(-300*(datas[i].value/scope));
minusValues +="<TD valign=top><DIV CLASS=MINUSDIV style='height:"+divHeight+"px'>";
plusValues+="<TD style='border-bottom:solid black 2px;'>";
}
}
str += plusValues+minusValues+"</TABLE>";
document.getElementById("CHARTTD").innerHTML = str;
}
</SCRIPT>
</head>
<body><TABLE border=1>
<TR><TD>2010年度销售记录
<TR><TD id=CHARTTD>
</TABLE> </body>
</html>
<SCRIPT>
drawChart();
</SCRIPT>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
var force_color = new Array();
var bg_color = new Array();
force_color[0]="#d1ffd1";
force_color[1]="#ffbbbb";
force_color[2]="#ffe3bb";
force_color[3]="#cff4f3";
force_color[4]="#d9d9e5";
force_color[5]="#ffc7ab";
force_color[6]="#ecffb7";bg_color[0]="#00ff00";
bg_color[1]="#ff0000";
bg_color[2]="#ff9900";
bg_color[3]="#33cccc";
bg_color[4]="#666699";
bg_color[5]="#993300";
bg_color[6]="#99cc00";
line_color="#69f";
var left_width=30;
var bottom_height=20;
function histogram(ar,space,width,height){
//柱阴影厚度
var thickness = space/2;
if (thickness<1)
thickness =0;
thickness = space;
//数据长度
var length = ar.length;
var iMax=0,iWidth=0,iHeight=0,tMax=0;//数据最大值
var i,j,obj,tmp;
var index=-1;
//验证
if (length==0) return;
for(i=0;i<length;i++){
obj = ar[i].split("|");
for(j=0;j<obj.length;j++){
tmp = parseInt(obj[j]);
if(tmp>iMax)
iMax =tmp;
}
}
tmp = iMax+'';
j = tmp.length;
if(iMax>9){
i= parseInt((iMax %100)/10);
if(i>4)
tMax =(parseInt(iMax/Math.pow(10,(j-1)))+1)*Math.pow(10,j-1);
else
tMax =(parseInt(iMax/Math.pow(10,(j-1)))+0.5)*Math.pow(10,j-1);
}else{
if(iMax>4)
tMax = 10;
else
tMax= 5;
}document.write('<table width="'+width+'" height="'+height+'" border="0" cellpadding="0" cellspacing="0"><tr>');
document.write('<td width="'+left_width+'" align="right" valign="bottom" height="'+(height-bottom_height)+'"><v:line style="position:absolute;left:0px;top:0px;right:0px;" alt="" to="'+left_width+'px,-'+(height-bottom_height)+'px" from="'+left_width+'px,0px"/>');
//画分隔线
iMax = 5;
tmp = ((height-bottom_height)/iMax);
i=1;
if(tmp>40){
iMax=10;
tmp = ((height-bottom_height)/iMax);
}
while(tmp>40){
iMax=10*(i++);
tmp = ((height-bottom_height)/iMax);
}
if(i>1) {
iMax-=10;
tmp = ((height-bottom_height)/iMax);
}document.write("<table width='100%' border='0' cellpadding='0' cellspacing='0' >");
for(i=iMax;i>=1;i--){
document.write("<tr><td height='"+tmp+"' align='center' style='border-top:1px solid #000000;' valign='top'>"+(tMax/iMax*i)+"</td></tr>");
}
document.write("</table><v:line to='0px,-"+(height-bottom_height)+"px'/> ");document.write('</td><td height="'+(height-bottom_height)+'" valign="bottom">');
document.write("<v:line strokecolor='"+line_color+"' to='15px,"+(tmp*(iMax)-15)+"px' from='15px,0px' />");
for(i=0;i<iMax;i++){
document.write("<v:line strokecolor='"+line_color+"' from='0px,"+(tmp*(i+1))+"' to='15px,"+(tmp*(i+1)-15)+"px' />");
document.write("<v:line strokecolor='"+line_color+"' to='15px,"+(tmp*(i+1)-15)+"' from='"+(width-left_width)+"px,"+(tmp*(i+1)-15)+"' />");
}
document.write('<v:rect alt="" style="position:absolute;width:'+(width-left_width)+';height:'+(height-bottom_height)+';z-index:-9" fillcolor="#9cf" stroked="f"><v:fill rotate="t" angle="-45" focus="100%" type="gradient"/></v:rect>');
document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="'+left_width/2+'"></td>');
//柱状图
tmp = (width-2*left_width)/length;
index = (height-bottom_height)/tMax;
for(i=0;i<length;i++){
obj = ar[i].split("|");
document.write("<td valign='bottom' width='"+tmp+"' align='center' height='"+(height-bottom_height)+"'>");
document.write('<v:group ID="group1" style="position:relative;WIDTH:'+tmp+'px;HEIGHT:'+(height-bottom_height)+'px;" coordsize = "'+tmp*10+','+(height-bottom_height)*10+'">');
document.write("<v:textbox style='position:absolute;left:0;top:-15;' inset='0px,0px,0px,0px' ><table cellspacing='3' cellpadding='0' width='100%' height='100%'><tr><td align='center'>"+formatNumber(obj[1],2)+"</td></tr></table></v:textbox>");
document.write('<v:rect style="position:relative;width:'+(tmp-space/2-15)*10+';height:'+index*parseInt(obj[1])*10+';" fillcolor="'+bg_color[i%bg_color.length]+'">');
//if(index*parseInt(obj[1])>10)document.write("<v:fill style='position:relative;' color2='"+force_color[i%force_color.length]+"' rotate='t' type='gradient'/>");
document.write("<o:extrusion v:ext='view' style='position:relative;' backdepth='"+thickness+"px' color='"+bg_color[i%bg_color.length]+"' on='t'/>");
document.write('</v:rect>');
document.write('</v:group>');
document.write("</td>");
}
document.write('</tr></table>');
//document.write('</v:rect>');document.write('</td></tr><tr><td height="'+bottom_height+'"></td>');
document.write('<td valign="bottom" height="'+bottom_height+'" width="'+(width-left_width)+'" style="border-top:1px solid #000000" >');
document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="'+left_width/2+'"></td>');
for(i=0;i<length;i++){
obj = ar[i].split("|");
document.write("<td width='"+tmp+"' align='center'>"+obj[0]+"</td>");
}
document.write('</td></tr></table>');
document.write('</td></tr></table>');
}function formatNumber(obj,length){
if(isNaN(obj)) return obj;
var tmp=obj+'';
var index = tmp.indexOf(".");
if(index!=-1){
return obj.substring(0,index+3);
}
else
return obj;}
//-->
</SCRIPT>
<style type="text/css">
v\:* { behavior: url(#default#VML) }
o\:* { behavior: url(#default#VML) }
.shape { behavior: url(#default#VML) }
body{
font-size:12px;
}
td{
font-size:12px;
}
</style>
</HEAD><BODY>
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr><td height="30" align="center" style="font-size:16px;font-weight:bold;color:#fc3a00;">发帖量统计</td></tr>
<tr>
<td ><script language="javascript">
var ar,space,width=500,height=400;
ar = new Array();
ar[0]="攒机买机|245";
ar[1]="硬件讨论|120";
ar[2]="笔记本专区|852";
ar[3]="数码产品|424";
ar[4]="操作系统|412";
ar[5]="软件下载|751";
ar[6]="影视下载|123";
space=20;
histogram(ar,space,width,height);</script></td>
</tr>
</table>
</BODY>
</HTML>