asp形成饼图问题

zhangmujing 2011-06-29 08:28:36
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%
'参数含义(数组,横坐标,纵坐标,图表的宽度,图表的高度,图表标题,单位)
function table2(stat_array,table_left,table_top,all_width,all_height,table_title,unit)
dim bg_color(12),pie(12)
bg_color(1)="#ff1919"
bg_color(2)="#ffff19"
bg_color(3)="#1919ff"
bg_color(4)="#19ff19"
bg_color(5)="#fc0"
bg_color(6)="#3cc"
bg_color(7)="#ff19ff"
bg_color(8)="#993300"
bg_color(9)="#f60"
bg_color(10)="#ff8c19"
bg_color(11)="#000000"
bg_color(12)="#666666"

num =ubound(stat_array,1)
allvalues=0
for i=1 to num
allvalues = allvalues+stat_array(i,1)
next
k=0
for i=1 to num-1
pie(i)=formatnumber(stat_array(i,1)/allvalues,4,-1)
k=k+pie(i)
next
pie(num)=formatnumber((1-k),4,-1)

response.Write "<v:shapetype id='Cake_3D' coordsize='21600,21600' o:spt='95' adj='11796480,5400' path='al10800,10800@0@0@2@14,10800,10800,10800,10800@3@15xe'></v:shapetype>"

response.Write "<v:shapetype id='3dtxt' coordsize='21600,21600' o:spt='136' adj='10800' path='m@7,l@8,m@5,21600l@6,21600e'> "
response.Write " <v:path textpathok='t' o:connecttype='custom' o:connectlocs='@9,0;@12,10800;@11,21600;@12,10800' o:connectangles='270,180,90,0'/>"
response.Write " <v:textpath on='t' fitshape='t'/>"
response.Write " <o:lock v:ext='edit' text='t' shapetype='t'/>"
response.Write "</v:shapetype>"

response.Write "<v:rect id='background' style='position:absolute;left:"&table_left&"px;top:"&table_top&"px;WIDTH:"&all_width&"px;HEIGHT:"&all_height&"px;' fillcolor='#EFEFEF' strokecolor='gray'>"
response.Write " <v:shadow on='t' type='single' color='silver' offset='3pt,3pt'/>"
response.Write "</v:rect>"

response.Write "<v:group ID='table' style='position:absolute;left:"&table_left&"px;top:"&table_top&"px;WIDTH:"&all_width&"px;HEIGHT:"&all_height&"px;' coordsize = '21000,11500'>"
response.Write " <v:Rect style='position:relative;left:500;top:200;width:20000;height:800'filled='false' stroked='false'>"
response.Write " <v:TextBox inset='0pt,0pt,0pt,0pt'>"
response.Write " <table width='100%' border='0' align='center' cellspacing='0'>"
response.Write " <tr>"
response.Write " <td align='center' valign='middle'><div style='font-size:10pt; font-family:宋体;'><B>"&table_title&"</B></div></td>"
response.Write " </tr>"
response.Write " </table>"
response.Write " </v:TextBox>"
response.Write " </v:Rect> "

response.Write " <v:rect id='back' style='position:relative;left:500;top:1000;width:20000; height:10000;' onmouseover='movereset(1)' onmouseout='movereset(0)' fillcolor='#9cf' strokecolor='#888888'>"
response.Write " <v:fill rotate='t' angle='-45' focus='100%' type='gradient'/>"
response.Write " </v:rect>"

response.Write " <v:rect id='back' style='position:relative;left:15000;top:1000;width:4500; height:10600;' fillcolor='#9cf' stroked='t' strokecolor='#0099ff'>"
response.Write " <v:fill rotate='t' angle='-175' focus='100%' type='gradient'/>"
response.Write " <v:shadow on='t' type='single' color='silver' offset='2pt,2pt'/>"
response.Write " </v:rect>"

response.Write " <v:Rect style='position:relative;left:15500;top:1000;width:4000;height:700' fillcolor='#000000' stroked='f' strokecolor='#000000'>"
response.Write " <v:TextBox inset='6pt,1pt,2pt,2pt' style='font-size:9pt;'><div align='left'><font color='#ffffff'><B>总数:"&allvalues&unit&"</B></font></div></v:TextBox>"
response.Write " </v:Rect> "
for i=1 to num
response.Write " <v:Rect id='rec"&i&"'style='position:relative;left:15400;top:"&i*9000/11+1450&";width:4300;height:800;display:none' fillcolor='#efefef' strokecolor='"&bg_color(i)&"'>"
response.Write " <v:fill opacity='.6' color2='fill darken(118)' o:opacity2='.6' rotate='t' method='linear sigma' focus='100%' type='gradient'/>"
response.Write " </v:Rect>"
response.Write " <v:Rect style='position:relative;left:15500;top:"&i*9000/11+1000&";width:600;height:700' fillcolor='"&bg_color(i)&"' stroked='f'/>"
response.Write " <v:Rect style='position:relative;left:16300;top:"&i*9000/11+1000&";width:3400;height:700' filled='f' stroked='f'>"
response.Write " <v:TextBox inset='0pt,4pt,0pt,0pt' style='font-size:8pt;'><div align='left'>"&stat_array(i,2)&":"&stat_array(i,1)&unit&"</div></v:TextBox>"
response.Write " </v:Rect> "
next

response.Write "</v:group>"

k1=180
k4=12
for i=1 to num
k2=360*pie(i)/2
k3=k1+k2
if k3>=360 then
k3=k3-360
end if
kkk=(-11796480*pie(i)+5898240)

k5=3.1414926*2*(180-(k3-180))/360
R=all_height/2
txt_x = table_left+all_height/8-30+R+R*sin(k5)*0.7
txt_y = table_top+all_height/14-39+R+R*cos(k5)*0.7*0.5

titlestr = " 名  称:"&stat_array(i,2)&"  数  值:"&stat_array(i,1)&unit&"  所占比例:"&pie(i)*100&"%  "
response.Write " <div style='cursor:hand;'>"
response.Write " <v:shape id='cake"&i&"' type='#Cake_3D' title='"&titlestr&"'"
response.Write " style='position:absolute;left:"&table_left+all_height/8&"px;top:"&table_top+all_height/14&"px;WIDTH:"&all_height&"px;HEIGHT:"&all_height&"px;rotation:"&k3&";z-index:"&k4&"'"
response.Write " adj='"&kkk&",0' fillcolor='"&bg_color(i)&"' onmouseover='moveup(cake"&i&","&(table_top+all_height/14)&",txt"&i&",rec"&i&")'; onmouseout='movedown(cake"&i&","&(table_top+all_height/14)&",txt"&i&",rec"&i&");'>"
response.Write " <v:fill opacity='60293f' color2='fill lighten(120)' o:opacity2='60293f' rotate='t' angle='-135' method='linear sigma' focus='100%' type='gradient'/>"
response.Write " <o:extrusion v:ext='view' on='t'backdepth='25' rotationangle='60' viewpoint='0,0'viewpointorigin='0,0' skewamt='0' lightposition='-50000,-50000' lightposition2='50000'/>"
response.Write " </v:shape>"
response.Write " <v:shape id='txt"&i&"' type='#3dtxt' style='position:absolute;left:"&txt_x&"px;top:"&txt_y&"px;z-index:20;display:none;width:50; height:18;' fillcolor='#ffffff'"
response.Write " onmouseover='ontxt(cake"&i&","&(table_top+all_height/14)&",txt"&i&",rec"&i&")'>"
response.Write " <v:fill opacity='60293f' color2='fill lighten(120)' o:opacity2='60293f' rotate='t' angle='-135' method='linear sigma' focus='100%' type='gradient'/>"
response.Write " <v:textpath style='font-family:'宋体';v-text-kern:t' trim='t' fitpath='t' string='"&pie(i)*100&"%'/>"
response.Write " <o:extrusion v:ext='view' backdepth='6pt' on='t' lightposition='0,0' lightposition2='0,0'/>"
response.Write " </v:shape>"
response.Write " </div>"
k1=k1+k2*2
if k1>=360 then
k1=k1-360
end if
if k1>180 then
k4=k4+1
else
k4=k4-1
end if
next
end function
%>
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<title></title>
<!--#include file="../include/SysLoginCheck.asp"-->
<STYLE>
v\:* { Behavior: url(#default#VML) }
o\:* { behavior: url(#default#VML) }
</STYLE>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!--
onit=true
num=0
function moveup(iteam,top,txt,rec){
temp=eval(iteam)
tempat=eval(top)
temptxt=eval(txt)
temprec=eval(rec)
at=parseInt(temp.style.top)
temprec.style.display = "";
if (num>27){
temptxt.style.display = "";
}
if(at>(tempat-28)&&onit){
num++
temp.style.top=at-1
Stop=setTimeout("moveup(temp,tempat,temptxt,temprec)",12)
}else{
return
}
}
function movedown(iteam,top,txt,rec){
temp=eval(iteam)
temptxt=eval(txt)
temprec=eval(rec)
clearTimeout(Stop)
temp.style.top=top
num=0
temptxt.style.display = "none";
temprec.style.display = "none";
}
function ontxt(iteam,top,txt,rec){
temp = eval(iteam);
temptxt = eval(txt);
temprec = eval(rec)
if (onit){
temp.style.top = top-28;
temptxt.style.display = "";
temprec.style.display = "";
}
}
function movereset(over){
if (over==1){
onit=false
}else{
onit=true
}
}
-->
</script>
<%
UnitName=cstr(session("UnitName"))
nf=cstr(session("nf"))
sqlSel="select * from mRecordCount where (UnitName='"& UnitName &"' and year='"& nf&"')"
set rs=server.createobject("adodb.recordset")
rs.open sqlSel,conn,1,1
%>
<%
dim total(12,2)

total(1,1)=clng(rs("jan"))
total(2,1)=clng(rs("feb"))
total(3,1)=clng(rs("mar"))
total(4,1)=clng(rs("apr"))
total(5,1)=clng(rs("may"))
total(6,1)=clng(rs("jun"))
total(7,1)=clng(rs("jul"))
total(8,1)=clng(rs("aug"))
total(9,1)=clng(rs("sep"))
total(10,1)=clng(rs("oct"))
total(11,1)=clng(rs("nov"))
total(12,1)=clng(rs("dec"))


total(1,2)="1月"
total(2,2)="2月"
total(3,2)="3月"
total(4,2)="4月"
total(5,2)="5月"
total(6,2)="6月"
total(7,2)="7月"
total(8,2)="8月"
total(9,2)="9月"
total(10,2)="10月"
total(11,2)="11月"
total(12,2)="12月"

if (total(1,1)=0 and total(2,1)=0 and total(3,1)=0 and total(4,1)=0 and total(5,1)=0 and total(6,1)=0 and total(7,1)=0 and total(8,1)=0 and total(9,1)=0 and total(10,1)=0 and total(11,1)=0 and total(12,1)=0) then
response.Write("新闻更新条数为0,无法形成饼图")
else
call table2(total,10,10,530,256,""& UnitName &""& nf&"年月更新新闻条数三维饼图","条")
end if
%>
<%
rs.close
set rs=nothing
conn.close
set conn=nothing%>
</body>
</html>
一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月 总数
 审计处  0   0   0   7   4   4   0   0   0   0   0   0   15 
大部分数据形成饼图没问题,就是这条数据形成饼图12月份数据显示占比例为-.01%,请教各位大侠!!!
...全文
112 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yousite1 2011-06-29
  • 打赏
  • 举报
回复
建议你换个思路,可以使用JS的饼状图(ASP只负责提供数据)
或者FLASH的饼状图。
zhangmujing 2011-06-29
  • 打赏
  • 举报
回复
回复2L:用了clng()转换函数。

另:为什么这条数据12月份的数据为0,而显示比例却是-.01%,其他单位数据也出现过12月份数据为0这种情况,但计算所占比例时都是正确的,就这几条数据12月份所占比例显示不正确,请教。。。
一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月 总数
 审计处  0   0   0   7   4   4   0   0   0   0   0   0   15 
学院   2   0   8   6   8   6   0   0   0   0   0   0   30 
 科处   5   0   18   4   1   7   0   0   0   0   0   0   35
党委   1   1   1   2   2   0   0   0   0   0   0   0   7 
教处   2   3   4   9   1   3   0   0   0   0   0   0   22 
亚细亚 2011-06-29
  • 打赏
  • 举报
回复
lz这一堆代码.
3L说的就是通过FLASH插件来处理,这个不错,很形象.
挨踢直男 2011-06-29
  • 打赏
  • 举报
回复
参考这个,使用方便,效果好
演示
下载
灬上海爽爷 2011-06-29
  • 打赏
  • 举报
回复
用CINT转换了么。
输出总数和12月的数据,慢慢断点调试吧。
ma1986 2011-06-29
  • 打赏
  • 举报
回复
这个程序还是你自己最清楚 最好是设置断点response.Write 输出检测哈各个阶段数据的大小了,一步一步的检测应该就晓得原因了

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧