# Drawing Graphs in ActionScript

Select the number of men and women to see a pie graph.

Experiment: Download the movie, and then change the color. Make a graph of the number of children and adults. Use appropriate names for all of the variables.

 `123456789101112131415161718192021222324252627282930` ```sldMen.addEventListener(Event.CHANGE, showGraph); sldWomen.addEventListener(Event.CHANGE, showGraph); var genderGraph:Sprite = new Sprite(); genderGraph.x=140; genderGraph.y=230; addChild(genderGraph); function showGraph(e:Event):void { lblMen.text=""+sldMen.value; lblWomen.text=""+sldWomen.value; var total:int=sldMen.value+sldWomen.value; //number of people=men+women var menPercent:int=sldMen.value/total*100; lblMenPercent.text=""+menPercent+"%"; var womenPercent:int=sldWomen.value/total*100; lblWomenPercent.text=""+womenPercent+"%"; genderGraph.graphics.clear(); genderGraph.graphics.lineStyle(1, 0x000000); //black lines between pieces var womenDegrees=360*womenPercent/100; //percent of 360 degrees piPiece(genderGraph,100,0,womenDegrees, 0xFF0000); //red from 0 to women degrees piPiece(genderGraph,100,womenDegrees,360, 0x0000FF); //blue for everything else } //showGraph function piPiece(graph,radius,startDeg, endDeg, color):void { graph.graphics.beginFill(color); graph.graphics.moveTo(0, 0); for (var i:int = startDeg; i<=endDeg; i++) { graph.graphics.lineTo(radius * Math.cos(i / 180 * Math.PI), radius * Math.sin(i / 180 * Math.PI)); } //draw line for each degree in piece graph.graphics.endFill(); } //piPiece```
CODE