2010-06-09 4 views
0

GroupingCollections 및 AdvancedDataGrids를 사용하여 XML 데이터를 그룹화했지만 차트에 데이터를 표시하는 방법을 알 수 없습니다.그룹화 된 XML 데이터를 Flex 파이 차트에 표시하려면 어떻게합니까?

기본적으로 내가하고 싶은 일은 카테고리 필드로 데이터를 그룹화하는 것입니다.이 필드는 빨간색 아래 두 개, 파란색 아래 한 개, 녹색 아래 한 개를 제공해야합니다. 이 데이터를 원형 차트에 입력 할 때는 적정 공간 (빨간색은 1/2, 파란색과 녹색은 각각 1/4)을 차지해야합니다. 콜 아웃으로 그룹 이름 (이 경우 카테고리)을 사용하려면 other_data 필드가 필요하지 않습니다.

제안 사항?

샘플 데이터 :

<row> 
    <category>red</category> 
    <other_data>this shouldn't really matter</other_data> 
</row> 
<row> 
    <category>blue</category> 
    <other_data>this shouldn't really matter</other_data> 
</row> 
<row> 
    <category>red</category> 
    <other_data>this shouldn't really matter</other_data> 
</row> 
<row> 
    <category>green</category> 
    <other_data>this shouldn't really matter</other_data> 
</row> 
+0

@Mike GroupingCollection으로 데이터를 가져 와서 AdvancedDataGrid로 출력 할 수 있었지만 제대로 그룹화되었지만 차트의 dataSource 특성을 정의하려고하면 오류가 발생하고 표시되지 않습니다. – mclaughlinj

답변

1

나는 총을 가지고 있습니다. 거기에 더 우아한 방법은 아마도, 또는 효율성,하지만 ...

개체

의의 ArrayCollection으로 XML을 돌려

{카테고리 : "빨간색", other_data : "중요하지 않다"} . . . 거기에서

... 그 외에는

var categoryGroup:GroupingCollection=new GroupingCollection(); 
categoryGroup.source=ac; // you're ArrayCollection 

var grouping:Grouping=new Grouping(); 
var groupingField:GroupingField=new GroupingField("category"); 
grouping.fields=[groupingField]; 

categoryGroup.grouping=grouping; 
categoryGroup.refresh(); 

var categoryAC:ArrayCollection=categoryGroup.getRoot() as ArrayCollection; 

chart.dataProvider=categoryAC; 

, 당신은 차트에 약간의 마법을해야 할 것이다 ...

<mx:PieChart id="chart" height="100%" width="100%"> 
    <mx:series> 
     <mx:PieSeries dataFunction="myDataFunction" labelFunction="myLabelFunction" labelPosition="callout"/> 
    </mx:series> 
</mx:PieChart> 

당신은 차트 기능 처리기있어

public function myDataFunction(series:Series, item:Object, fieldName:String):Object 
{ 
    return (item.children.length); 
} 

public function myLabelFunction(data:Object, field:String, index:Number, percentValue:Number):String 
{ 
    return data.GroupLabel; 
} 

너무 무거울 수 있지만 트릭을 수행하고 다른 시나리오로 확장 할 수 있습니다.

관련 문제