2011-12-12 62 views
0

我有使用Adobe Flash Builder制作的柱形图。动态添加列系列Adobe Flash

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

有没有人知道教程描述如何做到这一点在线?

谢谢

回答

2

你可以试试这个。

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

你的柱形图

<mx:ColumnChart id="columnChart"/> 
+0

太好了!它的作品谢谢!你能否也请告诉我如何向列添加填充颜色?然后我设置 – Tucker

+0

请参阅[http://www.adobe.com/livedocs/flex/3/html/charts_displayingdata_09.html#334719]和[http://livedocs.adobe.com/flex/3/html/ charts_types_06.html#164059] –

+0

链接被破坏,你可以再试一次吗? – Tucker

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>