动态添加列系列Adobe Flash

时间:2011-12-12 02:27:00

标签: flash flex charts adobe

我有一个使用Adobe Flash Builder制作的柱形图。

我希望能够动态添加(或删除)列系列。

有没有人知道如何在线进行此操作的教程?

由于

2 个答案:

答案 0 :(得分:2)

你可以试试这个。

var cs:ColumnSeries=new ColumnSeries();
cs.yField="yourYfield";
cs.xField="yourXfield";
cs.displayName="yourDisplayName";
columnChart.series.push(cs);

您的柱形图

<mx:ColumnChart id="columnChart"/> 

答案 1 :(得分:0)

尝试以下一个代码......难以理解但易于实现....

arrcolpie=new ArrayCollection();
            for(var i:int=0;i<arrCategoryName.length;i++)
            {
                var temp1:int;
                temp1 = i;

                addElementInCollection(arrCategoryName[i],arrRightCategoryMark[i],arrWrongCategoryMark[i],temp1);
            }   

            chartBar.dataProvider=arrcolpie;
            chartBar.validateNow();     

 public function addElementInCollection(catgName:String,crt:Number,wrg:Number,i:int):void
        {
            tempobj=new Object();

            tempobj.Label=catgName;
            tempobj.wronganswered=wrg;
            tempobj.rightanswer=crt;

            arrcolpie.addItemAt(tempobj,i);
        }


<mx:ColumnChart id="chartBar" height="100%" width="100%" dataProvider="{arrcolpie}" showDataTips="true"
                        columnWidthRatio="0.4">
                        <mx:horizontalAxis>
                            <mx:CategoryAxis categoryField="Label" id="a2" />
                        </mx:horizontalAxis>
                        <mx:horizontalAxisRenderer>
                            <mx:AxisRenderer axis="{a2}" />
                        </mx:horizontalAxisRenderer>
                        <mx:verticalAxis>
                            <mx:LinearAxis baseAtZero="true" minimum="0" maximum="100" />
                        </mx:verticalAxis>
                        <mx:series>
                            <mx:ColumnSeries yField="rightanswer" xField="Label" displayName="Correct Answers" />
                            <mx:ColumnSeries yField="wronganswered" xField="Label" displayName="Wrong Answers" />
                        </mx:series>    
                    </mx:ColumnChart>
                    <mx:Legend direction="horizontal">
                        <mx:LegendItem label="Correct Answers" fontWeight="bold" color="#082655">
                            <mx:fill>
                                <mx:SolidColor color="#00FF00" alpha=".3" />
                            </mx:fill>
                            <mx:stroke>
                                <mx:Stroke color="#00FF00" weight="2"/>
                            </mx:stroke>
                        </mx:LegendItem>
                        <mx:LegendItem label="Wrong Answers" fontWeight="bold" color="#082655">
                            <mx:fill>
                                <mx:SolidColor color="#FF0000" alpha=".3" />
                            </mx:fill>
                            <mx:stroke>
                                <mx:Stroke color="#FF0000" weight="2"/>
                            </mx:stroke>
                        </mx:LegendItem>
                    </mx:Legend>