PDA

View Full Version : Dynamic Pie Chart - Flash mx2004 Professional



Maryna
July 23rd, 2004, 05:08 AM
:m:
Hi all,
I have a question for you....I'm not able di draw a pie chart dynamically.
I have the Layer1 with a F3DPieChart, 4 input text and a button, I put 4 numer in the 4 inputtext (sum total = 100) and when I press the button I would like to see pie Chart to appear with 4 slices that rappresented my 4 numbers.unfortunately it doesn't happen.
This is the code on layer1:

[QUOTE]
var buttonListener = new Object();

buttonListener.click = function() {
var val;
var dp = new DataProviderClass();
val = _root.t1.text;
dp.addItem ({data:val, color:0xFF0000, label: "1"});
val = _root.t2.text;
dp.addItem ({data:val, color:0x00FF00, label: "2"});
val = _root.t3.text;
dp.addItem ({data:val, color:0x0000FF, label: "3"});
val = _root.t4.text;
dp.addItem ({data:val, color:0xFFFF00, label: "4"});
}
disegno = function(chart){
chart.removeAll();
chart.setDataProvider(dp);
delete dp;
}
_root.button.addEventListener("click", buttonListener);
Any help is apprecciate,
Maryna.

Jerryscript
July 27th, 2004, 11:54 AM
I'm not sure if you are using a component or have another function to draw the chart?

Here's a basic pie chart example in MX, it may need some tweeking for MX2004Pro, but hopefully it will help!

_root.createTextField('pieInput',1,10,75,250,400);
with(pieInput){
type='input';
wordwrap=multiline=background=border=true;
theformat=getTextFormat();
theformat.size=20;
setNewTextFormat(theformat);
setTextFormat(theFormat);
}

_root.colors=['0xff0000','0x00ff00','0x0000ff','0xffff00','0xff0 0ff','0x00ffff'];

createTextField('startPie',5,275,250,0,0);
with(startPie){
type='static';
selectable=false;
background=border=autosize=true;
backgroundColor='0xc6c6c6';
text='Create Pie Chart';
_xscale=_yscale=200;
}
createEmptyMovieClip('startP',6);
with(startP){
lineStyle(1,0x000000,1);
beginFill(0x000000,1);
lineTo(_root.startPie._width,0);
lineTo(_root.startPie._width,_root.startPie._heigh t);
lineTo(0,_root.startPie._height);
lineTo(0,0);
_x=_root.startPie._x;
_y=_root.startPie._y;
}
_root.startP.onRelease=function(){
pie=_root.pieInput.text.split(',');
pieValues=new Array();
total=0;
for(p in pie){
nameValue=pie[p].split('=');
total+=(nameValue[1]*1);
pieValues[nameValue[0]]=nameValue[1];
}
_root.createEmptyMovieClip('mc',10);
with(mc){
lastValue=0;
lineStyle(1,0x000000,100);
counter=0;
for(p in pieValues){
beginFill(_root.colors[counter],50);
counter++;
endValue=Math.round((pieValues[p]/total)*360)+lastValue;
for(c=lastValue;c<=endValue;c++){
x=Math.sin(Math.PI/180*c)*200+675;
y=Math.cos(Math.PI/180*c)*200+250;
if(c==0){
moveTo(675,250);
lineTo(x,y);
}else if (c==endValue){
lineTo(x,y);
lineTo(675,250);
endFill();
tx=Math.sin(Math.PI/180*((endValue-lastValue)/2+lastValue))*125+675;
ty=Math.cos(Math.PI/180*((endValue-lastValue)/2+lastValue))*125+250;
createTextField('pie'+counter,20+counter,tx,ty,0,0 );
with(eval('pie'+counter)){
type='static';
background=border=selectable=false;
autosize='center';
text=p;
theformat=getTextFormat();
theformat.bold=true;
theformat.size=15;
setTextFormat(theformat);
}
}else{
lineTo(x,y);
}
}
lastValue=endValue;
}
}
}

createTextField('instructions',7,0,10,500,50);
with(instructions){
type='static';
selectable=background=border=false;
html=multiline=wordwrap=autosize=true;
htmlText='<p align=\"center\"><font size=\"20\">Enter comma seperated name=value pairs in the text boxes.<br>Example: 1999=100000,2000=125000,2001=135000</font></p>';
}

Maryna
July 28th, 2004, 06:08 AM
Thanks for your reply,
I was not so precise, sorry. I'm using DevNet Resource Kit Volume 4.
It allow me to draw 3d Charts.
But I am not able to make it works, I read the on line help but there are very simple example so I can not use them.:a: