更新扇形统计图pie.as,并加多项目标签
作者 佚名技术
来源 服务器技术
浏览
发布时间 2012-07-07
先看看效果吧: 详细代码: /*---designbywhbin2009-8-16--- _radius:半径;_fontSize:字体的大小 用于画一个扇形统计图; */ packagemaths{ importFlash.display.Sprite; importflash.text.TextField; importflash.text.TextFieldAutoSize; importflash.text.TextFormat; importflash.events.MouseEvent; publicclassPieextendsSprite{ privatevarcolors:Array=[0x000000,0xff0000,0x00ff00,0x0000ff,0xffff00,0x00ffff,0xff00ff,0x999900,0x009900,0x9999ff]; privatevarradius:Number; privatevarpies:Array=[]; privatevartxts:Array=[]; privatevarangles:Array=[]; privatevarrects:Array=[]; privatevardatas:Array=[]; privatevarlabels:Array=[]; privatevartxtFormat:TextFormat; privatevarpie:Sprite; privatevarrect:Sprite; privatevartxt:TextField; publicfunctionPie(_radius:Number=40,_fontSize:uint=15){ radius=_radius; txtFormat=newTextFormat(); txtFormat.size=_fontSize; } publicfunctiondrawPies(_array:Array){ foreach(varobjin_array){ datas.push(obj.data); labels.push(obj.label); } //计算圆心角: varsumAngle:Number=0; foreach(varangleindatas){ sumAngle+=angle; } foreach(varaindatas){ angles.push((a/sumAngle)*2*Math.PI); } //画扇形图: for(vari:uint=0;i<datas.length;i++){; pie=newSprite(); pie.graphics.lineStyle(1,0); pie.graphics.beginFill(colors[i%colors.length]); pie.graphics.moveTo(0,0); sumAngle=0; for(varj:uint=0;j<i;j++){; sumAngle+=angles[j]; } pie.graphics.lineTo(radius*Math.cos(sumAngle),radius*Math.sin(sumAngle)); for(varangle1:Number=0;angle1<angles[i]+0.05;angle1+=0.05){; pie.graphics.lineTo(radius*Math.cos(angle1+sumAngle),radius*Math.sin(angle1+sumAngle)); } pie.graphics.lineTo(0,0); pie.addEventListener(flash.events.MouseEvent.MOUSE_OVER,mouseOnPie); pie.addEventListener(flash.events.MouseEvent.MOUSE_OUT,mouseOutPie); addChild(pie); pie.alpha=0.5; pies.push(pie); drawRects(i); } }//endoffunctiondrawPies privatefunctiondrawRects(num:uint){ varrowNum:uint=num%4; varlistNum:uint=uint(num/4); rect=newSprite(); rect.graphics.lineStyle(1,0); rect.graphics.beginFill(colors[num%colors.length]); rect.graphics.drawRect(0,0,20,20); rect.graphics.endFill(); addChild(rect); rect.x=radius+40+listNum*70; rect.y=-(radius+10)+rowNum*(20+5); rect.alpha=0.5; rect.addEventListener(flash.events.MouseEvent.MOUSE_OVER,mouseOnRect); rect.addEventListener(flash.events.MouseEvent.MOUSE_OUT,mouseOutRect); // txt=newTextField(); txt.defaultTextFormat=txtFormat; txt.text=labels[num]+":"+String(Math.round(1000*angles[num]/(2*Math.PI))/10)+"%"; txt.autoSize=flash.text.TextFieldAutoSize.LEFT; txt.x=22; txt.mouseEnabled=false; rect.addChild(txt); txts.push(txt); rects.push(rect); }//endofdrawRects privatevarindex:Number; privatefunctionmouseOnRect(e:MouseEvent){ ((e.target).getChildAt(0)).border=true; e.target.alpha=1; index=rects.indexOf(e.target); pies[index].alpha=1; }//endofmouseOnPie privatefunctionmouseOutRect(e:MouseEvent){ e.target.alpha=0.5; foreach(vartintxts){ t.border=false;} foreach(var |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于更新扇形统计图pie.as,并加多项目标签的所有评论