2011-10-11 60 views
0

動態檢測LineSeries這是我的數組集合創造線型圖

[Bindable]private var Projects:ArrayCollection = new ArrayCollection([ 
       { Department: "Software", TotalProjects: 73,Completed:30,Inprogress:30,Approved:13}, 
       { Department: "XML",TotalProjects: 50,Completed:20,Inprogress:20,Approved:10}, 
       { Department: "Publishing",TotalProjects: 25,Completed:5,Inprogress:10,Approved:10}, 
       { Department: "Indesign", TotalProjects: 70,Completed:30,Inprogress:30,Approved:10}, 
       { Department: "Imaging", TotalProjects: 42,Completed:30,Inprogress:10,Approved:2}]); 

折線圖線系列:

<mx:series> 


<mx:LineSeries id="cs1" 
            yField="TotalProjects" 
            xField="Department" 
            displayName="TotalProjects"> 

       </mx:LineSeries> 
       <mx:LineSeries id="cs2" 
           yField="Inprogress" 
           xField="Department" 
           displayName="Inprogress"> 

       </mx:LineSeries> 
       <mx:LineSeries id="cs3" 
           yField="Completed" 
           xField="Department" 
           displayName="Completed"> 

       </mx:LineSeries> 
       <mx:LineSeries id="cs4" 
           yField="Approved" 
           xField="Department" 
           displayName="Approved"> 

       </mx:LineSeries> 


      </mx:series> 

如何創建mx:LineSeries動態取決於陣列收藏價值。現在只有4行系列在那裏,但有時我必須顯示更多按照數組集合值更改前:如果多一個狀態HoldProject添加到數組集合?

回答

2
var series:Array=[]; 
for (var prop:String in Projects[0]) 
    if (prop != "Department") { 
     var ls:LineSeries=new LineSeries(); 
     ls.yField=prop; 
     ls.xField="Department"; 
     s.displayName=prop; 
     series.push(ls); 
    } 
myChart.series=series; 

在這種情況下,dataProvider中的每個項目都應該具有相同的屬性集。

+0

OK.if我收到具有不同屬性的數組集合對象,每次如何遍歷數組集合項並創建線條系列? –

+0

您能否提供更多詳細信息?因爲,我們怎麼知道,每個項目應該使用哪個字段作爲yField? –

+0

@ Timofei Davydik在給出'Department'的數組集合中是很常見的,但剩下的字段有時只有3個狀態發生變化:'Completed','hold',''approved'和一些更多的'Completed','hold','approved', '刪除','初始','延期'等。 –