来自:http://www.cnblogs.com/ddw1997/archive/2009/07/24/1530597.html
DrawPieGraph.as
1package CYPL.Graphics{ import fl.transitions.Tween; import fl.transitions.easing.*; import fl.transitions.TweenEvent; import flash.display.MovieClip; import flash.display.Sprite; import flash.display.Shape; import flash.display.Graphics; import flash.events.MouseEvent; import flash.text.*; public class DrawPieGraph extends MovieClip { 13 //存放shape对象 private var __contain:Object; //设置角度从-90开始 private var R:int = -90; private var D:uint = 30; private var _shape:Shape; //初始饼图的圆心位置 private var _x0:Number; private var _y0:Number; //椭圆饼图的长轴与短轴长度 private var _a:Number; private var _b:Number; //饼图的厚度 private var _h:Number; //透明度 private var _alpha:Number; //数据列表 private var _nameList:Array; private var _dataList:Array; private var _colorList:Array; private var _angleList:Array; private var _depthList:Array; // private var _tween1:Tween; private var _tween2:Tween; private var showorder:Boolean; private var percent:Boolean; private var fontcolor:uint; private var orderx:Number; private var ordery:Number; private var orderxy:Number; private var shape:Array; private var sp:Sprite; private var Rect:Sprite; private var namelabel:TextField; 49 /**//**==========================15个参数================================================================================== *@param:x0>圆心x坐标=========1 *@param:y0>圆心y坐标=========2 *@param:a>长轴===============3 *@param:b>短轴================4 *@param:h>厚度=================5 *@alpha:Number>透明度===============6 *@param:dataList>数据列表(有默认值)===============7 *@param:dataList>颜色列表(有默认值)==================8 *@param:dataList>名称列表(有默认值)==================9 *@param:dataList>是否显示百分比==================10 *@param:dataList>百分比字体颜色==================11 *@param:dataList>是否显示图例==================12 *@param:dataList>图例x坐标==================13 *@param:dataList>图例y坐标==================14 *@param:dataList>图例间距==================15 */ public function DrawPieGraph(x0:Number,y0:Number,a:Number,b:Number,h:Number,Alpha:Number,dataList:Array,colorList:Array,nameList:Array,ifpercent:Boolean,perColor:uint ,ifshoworder:Boolean, myorderx:Number, myordery:Number, myorderxy:Number) { _x0 = x0; _y0 = y0; _a = a; _b = b; _h = h; percent = ifpercent; fontcolor = perColor; showorder = ifshoworder; orderx = myorderx; ordery = myordery; orderxy = myorderxy; _nameList = nameList; _alpha = Alpha; _colorList = colorList == null ? [0x330099,0x04D215,0x7E9B06,0x990065,0xFF9E01,0xFF6600,0xFE9A9A,0xA00101,0xFCD202]:colorList; sp=new Sprite(); sp.mouseEnabled = sp.mouseChildren = false; ToolTip.init(sp); render(dataList); } public function render(dataList:Array ) { R = -90; setAngleList(dataList); clearAll(); drawRect(); drawPie(); } 96 private function setAngleList(dataList:Array):void { _dataList = dataList == null ? [1,1,1,1,1,1,1,1]:dataList; _angleList = []; var totalData:int; var len:uint = _dataList.length; for (var j:uint=0; j < len; j++) { totalData += _dataList[j]; } if (totalData==0) { for (j=0; j < len; j++) { _dataList[j]=1; totalData=len; } } 111 for (j=0; j < len; j++) { if (j==len-1) { _angleList.push([R,270]); } else { var r:uint=Math.floor(_dataList[j]/totalData*360); var posR:int=R+r; _angleList.push([R,posR]); R=posR; } } for (j=len-1; j >0; j--) { if(_dataList[j]!=0){ _angleList.splice(j, 1,[_angleList[j][0],270]); break; } } 131 } private function setDepths():void { _depthList=[]; var len:uint=_angleList.length; for (var j:uint=0; j < len; j++) { var minJ:Number=_angleList[j][0]; var maxJ:Number=_angleList[j][1]; switch (true) { case minJ >= -90 && minJ <= 90 && maxJ<=90 : _depthList[j]=minJ; break; default : _depthList[j]=1000-minJ; } } _depthList=_depthList.sort(Array.NUMERIC|Array.RETURNINDEXEDARRAY); for (j=0; j"; //下划线效果namelabel.htmlText= ""+""+_nameList[jk]+""+""; addChild(namelabel); var beginx:Number=orderx; var beginy:Number=ordery; var jianxy:Number=orderxy+12;//图例方块的边长 if (_dataList[jk]!=0) { Rect.graphics.beginFill(_colorList[jk],1); } Rect.graphics.lineStyle(1,0xffffff,1); Rect.graphics.moveTo(0,0); Rect.graphics.lineTo(12,0); Rect.graphics.lineTo(12,12); Rect.graphics.lineTo(0,12); Rect.graphics.lineTo(0,0); if (_dataList[jk]!=0) { Rect.graphics.endFill(); } Rect.x=beginx; Rect.y=beginy+jianxy*jk; namelabel.x=Rect.x+20; namelabel.y=Rect.y-4; _dataList[jk]!=0?Rect.addEventListener(MouseEvent.MOUSE_OVER,onMouseDownX):0; } } 192 } public function drawPie():void { __contain={}; var len:uint=_angleList.length; var step:uint=1; 199 shape=new Array(); for (var j:uint=0; j < len; j++) { 202 __contain["shape"+j]=new MovieClip ; addChild(__contain["shape"+j]); shape.push(__contain["shape" + j]); if (_dataList[j]!=0) { 207 __contain["shape"+j].out=false; //设置中心角,方便以下进行中点移动 __contain["shape"+j].r=(_angleList[j][0]+_angleList[j][1])/2; __contain["shape"+j].addEventListener(MouseEvent.MOUSE_DOWN,onMouseDownX); 212 ToolTip.register(__contain["shape"+j], _nameList[j]); __contain["shape"+j].name="shape"+j; var drakColor:uint=getDarkColor(_colorList[j]);//深色 var g:Graphics=__contain["shape"+j].graphics; //====================================================================================================先画百分比 if (percent) { /**//*g.beginFill(0x000000,_alpha); g.lineStyle(1, 0x000000, 1); if(0<(_angleList[j][0]+ _angleList[j][1])/2 &&(_angleList[j][0]+ _angleList[j][1])/2<180 ){ g.moveTo(getRPoint(_x0, _y0+_h, _a, _b, (_angleList[j][0] + _angleList[j][1] ) / 2).x,getRPoint(_x0, _y0+_h, _a, _b, (_angleList[j][0] + _angleList[j][1] ) / 2).y); g.lineTo(getRPoint(_x0,_y0+_h, 20*_a, 20*_b, (_angleList[j][0] + _angleList[j][1] ) / 2).x,getRPoint(_x0, _y0+_h, 20*_a, 20*_b, (_angleList[j][0] + _angleList[j][1] ) / 2).y); }else{ g.moveTo(getRPoint(_x0, _y0, _a, _b, (_angleList[j][0] + _angleList[j][1] ) / 2).x,getRPoint(_x0, _y0, _a, _b, (_angleList[j][0] + _angleList[j][1] ) / 2).y); g.lineTo(getRPoint(_x0,_y0, 20*_a, 20*_b, (_angleList[j][0] + _angleList[j][1] ) / 2).x,getRPoint(_x0, _y0, 20*_a, 20*_b, (_angleList[j][0] + _angleList[j][1] ) / 2).y); } g.endFill()*/ var total:Number=0; for (var jh:uint=0; jh <_dataList.length; jh++) { total+=_dataList[jh]; } var prelabel:TextField=new TextField ; prelabel.text=String(Math.floor((_dataList[j]/total)*10000)/100)+"%"; prelabel.selectable=false; prelabel.background=true; prelabel.backgroundColor=drakColor; __contain["shape"+j].addChild(prelabel); var myformat:TextFormat = new TextFormat(); myformat.font="Verdana"; myformat.size=12; myformat.color=0xffffff; prelabel.setTextFormat(myformat); prelabel.gridFitType="pixel"; prelabel.antiAliasType="advanced"; prelabel.sharpness=-400; prelabel.autoSize=TextFieldAutoSize.LEFT; var zhongwei:Number=(_angleList[j][0] + _angleList[j][1] ) / 2; if (zhongwei>0&&zhongwei<90) { prelabel.x=getRPoint(_x0,_y0+_h,_a,_b,zhongwei).x; prelabel.y=getRPoint(_x0,_y0+_h,_a,_b,zhongwei).y; } else if (zhongwei>90 && zhongwei<180) { prelabel.x=getRPoint(_x0,_y0+_h,_a,_b,zhongwei).x-prelabel.width; prelabel.y=getRPoint(_x0,_y0+_h,_a,_b,zhongwei).y; } else if (zhongwei>180 && zhongwei<270) { prelabel.x=getRPoint(_x0,_y0,_a,_b,zhongwei).x-prelabel.width; prelabel.y=getRPoint(_x0,_y0,_a,_b,zhongwei).y-prelabel.height; } else if (zhongwei>-90 && zhongwei<0) { prelabel.x=getRPoint(_x0,_y0,_a,_b,zhongwei).x; prelabel.y=getRPoint(_x0,_y0,_a,_b,zhongwei).y-prelabel.height; } else if (zhongwei == 0) { prelabel.x=getRPoint(_x0,_y0,_a,_b,zhongwei).x; prelabel.y=getRPoint(_x0,_y0,_a,_b,zhongwei).y-prelabel.height/2; } else if (zhongwei == 90) { prelabel.x=getRPoint(_x0,_y0+_h,_a,_b,zhongwei).x-prelabel.width/2; prelabel.y=getRPoint(_x0,_y0+_h+1,_a,_b,zhongwei).y; } else if (zhongwei == 180) { prelabel.x=getRPoint(_x0,_y0,_a,_b,zhongwei).x-prelabel.width; prelabel.y=getRPoint(_x0,_y0,_a,_b,zhongwei).y-prelabel.height/2; } } //-------------------------------------- //内弧 //g.lineStyle(1); //先画底 //内弧 g.lineStyle(1,drakColor,_alpha); g.beginFill(_colorList[j],_alpha); g.moveTo(_x0,_y0+_h); var r:Number=_angleList[j][0]; var minR:Number=r; var maxR:int=_angleList[j][1]; while (r + step < maxR) { g.lineTo(getRPoint(_x0,_y0 + _h,_a,_b,r).x,getRPoint(_x0,_y0 + _h,_a,_b,r).y); r+=step; } g.lineTo(getRPoint(_x0,_y0 + _h,_a,_b,maxR).x,getRPoint(_x0,_y0 + _h,_a,_b,maxR).y); g.endFill(); //画内侧面 g.lineStyle(1,drakColor,_alpha); g.beginFill(drakColor,_alpha); g.moveTo(_x0,_y0+_h); g.lineTo(getRPoint(_x0,_y0 + _h,_a,_b,minR).x,getRPoint(_x0,_y0 + _h,_a,_b,minR).y); g.lineTo(getRPoint(_x0,_y0,_a,_b,minR).x,getRPoint(_x0,_y0,_a,_b,minR).y); g.lineTo(_x0,_y0); g.endFill(); //画外侧面 g.lineStyle(1,drakColor,1); g.beginFill(drakColor,_alpha); g.moveTo(_x0,_y0+_h); g.lineTo(getRPoint(_x0,_y0 + _h,_a,_b,maxR).x,getRPoint(_x0,_y0 + _h,_a,_b,maxR).y); g.lineTo(getRPoint(_x0,_y0,_a,_b,maxR).x,getRPoint(_x0,_y0,_a,_b,maxR).y); g.lineTo(_x0,_y0); g.endFill(); //画外弧侧面 //画外弧侧面 //-------------------------------- //下边高 //下边外侧边高 if (minR<=0&&maxR>=0&&maxR<=180) { //解决90度时外侧面,显示事实为90度,实际为0度,因为我们整个旋转了-90度; g.lineStyle(1,drakColor,1); g.beginFill(drakColor,1); g.moveTo(getRPoint(_x0,_y0 + _h,_a,_b,minR).x,getRPoint(_x0,_y0 + _h,_a,_b,minR).y); var k:Number=minR; while (k < 0) { k+=step; g.lineTo(getRPoint(_x0,_y0 + _h,_a,_b,k).x,getRPoint(_x0,_y0 + _h,_a,_b,k).y); } g.lineTo(getRPoint(_x0,_y0,_a,_b,0).x,getRPoint(_x0,_y0,_a,_b,0).y); while (k > minR) { k-=step; g.lineTo(getRPoint(_x0,_y0,_a,_b,k).x,getRPoint(_x0,_y0,_a,_b,k).y); } g.endFill(); g.lineStyle(1,drakColor,1); g.beginFill(drakColor,1); g.moveTo(getRPoint(_x0,_y0 + _h,_a,_b,0).x,getRPoint(_x0,_y0 + _h,_a,_b,0).y); k=0; while (k < maxR) { k+=step; g.lineTo(getRPoint(_x0,_y0 + _h,_a,_b,k).x,getRPoint(_x0,_y0 + _h,_a,_b,k).y); } g.lineTo(getRPoint(_x0,_y0,_a,_b,maxR).x,getRPoint(_x0,_y0,_a,_b,maxR).y); while (k > 0) { k-=step; g.lineTo(getRPoint(_x0,_y0,_a,_b,k).x,getRPoint(_x0,_y0,_a,_b,k).y); } g.endFill(); } else if (maxR >= 180 && minR <= 180 && minR >= 0) { //解决180度时外侧面,显示事实为270度,实际为180度,因为我们整个旋转了-90度; g.lineStyle(1,drakColor,1); g.beginFill(drakColor,1); g.moveTo(getRPoint(_x0,_y0 + _h,_a,_b,minR).x,getRPoint(_x0,_y0 + _h,_a,_b,minR).y); k=minR; while (k < 180) { k+=step; g.lineTo(getRPoint(_x0,_y0 + _h,_a,_b,k).x,getRPoint(_x0,_y0 + _h,_a,_b,k).y); } g.lineTo(getRPoint(_x0,_y0,_a,_b,180).x,getRPoint(_x0,_y0,_a,_b,180).y); while (k > minR) { k-=step; g.lineTo(getRPoint(_x0,_y0,_a,_b,k).x,getRPoint(_x0,_y0,_a,_b,k).y); } g.endFill(); g.lineStyle(1,drakColor,1); g.beginFill(drakColor,1); g.moveTo(getRPoint(_x0,_y0 + _h,_a,_b,180).x,getRPoint(_x0,_y0 + _h,_a,_b,180).y); k=180; while (k < maxR) { k+=step; g.lineTo(getRPoint(_x0,_y0 + _h,_a,_b,k).x,getRPoint(_x0,_y0 + _h,_a,_b,k).y); } g.lineTo(getRPoint(_x0,_y0,_a,_b,maxR).x,getRPoint(_x0,_y0,_a,_b,maxR).y); while (k > 180) { k-=step; g.lineTo(getRPoint(_x0,_y0,_a,_b,k).x,getRPoint(_x0,_y0,_a,_b,k).y); } g.endFill(); } else if (minR <= 0 && maxR >= 180) { //解决同时处于0度和180度的情况 g.lineStyle(1,drakColor,1); g.beginFill(drakColor,1); g.moveTo(getRPoint(_x0,_y0 + _h,_a,_b,minR).x,getRPoint(_x0,_y0 + _h,_a,_b,minR).y); k=minR; while (k < 0) { k+=step; g.lineTo(getRPoint(_x0,_y0 + _h,_a,_b,k).x,getRPoint(_x0,_y0 + _h,_a,_b,k).y); } g.lineTo(getRPoint(_x0,_y0,_a,_b,0).x,getRPoint(_x0,_y0,_a,_b,0).y); while (k > minR) { k-=step; g.lineTo(getRPoint(_x0,_y0,_a,_b,k).x,getRPoint(_x0,_y0,_a,_b,k).y); } g.endFill(); g.lineStyle(1,drakColor,1); g.beginFill(drakColor,1); g.moveTo(getRPoint(_x0,_y0 + _h,_a,_b,0).x,getRPoint(_x0,_y0 + _h,_a,_b,0).y); k=0; while (k < 180) { k+=step; g.lineTo(getRPoint(_x0,_y0 + _h,_a,_b,k).x,getRPoint(_x0,_y0 + _h,_a,_b,k).y); } g.lineTo(getRPoint(_x0,_y0,_a,_b,180).x,getRPoint(_x0,_y0,_a,_b,180).y); while (k > 0) { k-=step; g.lineTo(getRPoint(_x0,_y0,_a,_b,k).x,getRPoint(_x0,_y0,_a,_b,k).y); } g.endFill(); g.lineStyle(1,drakColor,1); g.beginFill(drakColor,1); g.moveTo(getRPoint(_x0,_y0 + _h,_a,_b,180).x,getRPoint(_x0,_y0 + _h,_a,_b,180).y); k=180; while (k < maxR) { k+=step; g.lineTo(getRPoint(_x0,_y0 + _h,_a,_b,k).x,getRPoint(_x0,_y0 + _h,_a,_b,k).y); } g.lineTo(getRPoint(_x0,_y0,_a,_b,maxR).x,getRPoint(_x0,_y0,_a,_b,maxR).y); while (k > 180) { k-=step; g.lineTo(getRPoint(_x0,_y0,_a,_b,k).x,getRPoint(_x0,_y0,_a,_b,k).y); } g.endFill(); } else { g.lineStyle(1,drakColor,1); g.beginFill(drakColor,1); g.moveTo(getRPoint(_x0,_y0 + _h,_a,_b,minR).x,getRPoint(_x0,_y0 + _h,_a,_b,minR).y); k=minR; while (k < maxR) { k+=step; g.lineTo(getRPoint(_x0,_y0 + _h,_a,_b,k).x,getRPoint(_x0,_y0 + _h,_a,_b,k).y); } //g.lineTo(getRPoint(_x0, _y0+_h, _a, _b, maxR).x, getRPoint(_x0, _y0+_h, _a, _b, maxR).y); g.lineTo(getRPoint(_x0,_y0,_a,_b,k).x,getRPoint(_x0,_y0,_a,_b,k).y); while (k > minR) { k-=step; g.lineTo(getRPoint(_x0,_y0,_a,_b,k).x,getRPoint(_x0,_y0,_a,_b,k).y); } g.endFill(); } //画上表面 g.lineStyle(1,_colorList[j],_alpha); g.beginFill(_colorList[j],_alpha); g.moveTo(_x0,_y0); r=minR; while (r + step < maxR) { g.lineTo(getRPoint(_x0,_y0,_a,_b,r).x,getRPoint(_x0,_y0,_a,_b,r).y); r+=step; } g.lineTo(getRPoint(_x0,_y0,_a,_b,maxR).x,getRPoint(_x0,_y0,_a,_b,maxR).y); g.endFill(); } } setDepths(); addChild(sp);//提示标签加在这里,防止标签被饼块遮住 } private function onMouseDownX(e:MouseEvent):void { var TG:MovieClip=shape[Number(e.currentTarget.name.substring(5))] as MovieClip; var posX:Number=getRPoint(0,0,D,D,TG.r).x; var posY:Number=getRPoint(0,0,D,D,TG.r).y; if (! TG.out) { TG.removeEventListener(MouseEvent.MOUSE_DOWN,onMouseDownX); TG["tweenX"]=new Tween(TG,"x",Bounce.easeOut,0,posX,1.5,true); TG["tweenY"]=new Tween(TG,"y",Bounce.easeOut,0,posY,1.5,true); } else { TG.removeEventListener(MouseEvent.MOUSE_DOWN,onMouseDownX); TG["tweenX"]=new Tween(TG,"x",Bounce.easeOut,TG.x,0,1,true); TG["tweenY"]=new Tween(TG,"y",Bounce.easeOut,TG.y,0,1,true); } TG["tweenX"].addEventListener(TweenEvent.MOTION_FINISH,onMotionFinish); } 461 //=============================================================================== private function onMotionFinish(e:TweenEvent):void { var TG:MovieClip=e.currentTarget.obj as MovieClip; TG["tweenX"].removeEventListener(TweenEvent.MOTION_FINISH,onMotionFinish); TG.out=! TG.out?true:false; TG.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDownX); } private function getDarkColor(color:uint):uint { var r:uint=color>>16&0xFF/1.3;//设置red通道的值 var g:uint=color>>8&0xFF/1.3;//设置green通道的值 var b:uint=color&0xFF/1.1;//设置blue通道的值 return r << 16 | g << 8 | b;//得到新颜色 } private function getRPoint(x0:Number,y0:Number,a:Number,b:Number,r:Number):Object { r=r*Math.PI/180; return {x:Math.cos(r) * a + x0,y:Math.sin(r) * b + y0}; } public function get contain():Object { return __contain; } private function clearAll():void {//清除内容 var len:uint=_dataList.length; while(this.numChildren!=0){ removeChildAt(0); } for (var j:uint=0; j
ToolTip.as
package CYPL.Graphics { import flash.accessibility.AccessibilityProperties; import flash.display.*; import flash.events.*; import flash.geom.Point; import flash.text.*; /** * @link [email protected] * @author Kinglong * @version 0.1 * @since 20090608 * @playerversion fp9+ * 热区提示 */ public class ToolTip extends Sprite { private static var instance:ToolTip = null; private var label:TextField; private var area:DisplayObject; public function ToolTip() { label = new TextField(); label.autoSize = TextFieldAutoSize.LEFT; label.selectable = false; label.multiline = false; label.wordWrap = false; label.defaultTextFormat = new TextFormat("宋体", 12, 0x666666); label.text = "提示信息"; label.x = 5; label.y = 2; addChild(label); redraw(); visible = false; mouseEnabled = mouseChildren = false; } private function redraw() { var w:Number = 10 + label.width; var h:Number = 4 + label.height; this.graphics.clear(); this.graphics.beginFill(0x000000, 0.4); this.graphics.drawRoundRect(3, 3, w, h, 5, 5); this.graphics.moveTo(6, 3 + h); this.graphics.lineTo(12, 3 + h); this.graphics.lineTo(9, 8 + h); this.graphics.lineTo(6, 3 + h); this.graphics.endFill(); this.graphics.beginFill(0xffffff); this.graphics.drawRoundRect(0, 0, w, h, 5, 5); this.graphics.moveTo(3, h); this.graphics.lineTo(9, h); this.graphics.lineTo(6, 5 + h); this.graphics.lineTo(3, h); this.graphics.endFill(); } public static function init(base:DisplayObjectContainer) { if (instance == null) { instance = new ToolTip(); base.addChild(instance); } } public static function register(area:DisplayObject, message:String):void { if(instance != null){ var prop:AccessibilityProperties = new AccessibilityProperties(); prop.description = message; area.accessibilityProperties = prop; area.addEventListener(MouseEvent.MOUSE_OVER, instance.handler); } } public static function unregister(area:DisplayObject):void { if (instance != null) { area.removeEventListener(MouseEvent.MOUSE_OVER, instance.handler); } } public function show(area:DisplayObject):void { this.area = area; this.area.addEventListener(MouseEvent.MOUSE_OUT, this.handler); this.area.addEventListener(MouseEvent.MOUSE_MOVE, this.handler); label.text = area.accessibilityProperties.description; redraw(); } public function hide():void { this.area.removeEventListener(MouseEvent.MOUSE_OUT, this.handler); this.area.removeEventListener(MouseEvent.MOUSE_MOVE, this.handler); this.area = null; visible = false; } public function move(point:Point):void { var lp:Point = this.parent.globalToLocal(point); this.x = lp.x - 6; this.y = lp.y - label.height - 12; if(!visible){ visible = true; } } private function handler(event:MouseEvent):void { switch(event.type) { case MouseEvent.MOUSE_OUT: this.hide(); break; case MouseEvent.MOUSE_MOVE: this.move(new Point(event.stageX, event.stageY)); break; case MouseEvent.MOUSE_OVER: this.show(event.currentTarget as DisplayObject); this.move(new Point(event.stageX, event.stageY)) break; } } } }
时间轴代码
import CYPL.Graphics.*; /**==========================15个参数================================================================================== *@param:x0>圆心x坐标=========1 *@param:y0>圆心y坐标=========2 *@param:a>长轴===============3 *@param:b>短轴================4 *@param:h>厚度=================5 *@alpha:Number>透明度===============6 *@param:dataList>数据列表(有默认值)===============7 *@param:dataList>颜色列表(有默认值)==================8 *@param:dataList>名称列表(有默认值)==================9 *@param:dataList>是否显示百分比==================10 *@param:dataList>百分比字体颜色==================11 *@param:dataList>是否显示图例==================12 *@param:dataList>图例x坐标==================13 *@param:dataList>图例y坐标==================14 *@param:dataList>图例间距==================15 */ var dataList:Array = [100,100,100,100,100,100]; //var dataList:Array = [0,0,100,200,100,300,100,0,0]; for (var i:int=0; i<6; i++) { this["txt" + i].restrict = "0-9"; } var nameList:Array = ["星光大道","春节晚会","同一首歌","梦想剧场","NBA 赛场","非常“6+1”"]; //trace(dataList+"..list"); var pie:DrawPieGraph = new DrawPieGraph(200,240,120,80,40,1,dataList,null,nameList,true,0xffffff,true,440,240,10); addChild(pie); btn.addEventListener(MouseEvent.CLICK,fun); btn.setStyle("textFormat",new TextFormat("宋体",14,0xffffff)); function fun(e):void { for (var i:int=0; i<6; i++) { dataList[i] = Number(this["txt" + i].text); } //pie.clearAll() pie.render(dataList); }