2011-12-12 58 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>