I have a dynamic ArrayCollection that will contain a unknown number of objects of type MyObj: class MyObj { type:String value:long } where each MyObj object has a different value of "type". how can I build a single stacked bar from this array where each section of the stacked bar represents an object of MyObj (represents a "type") and its length is the value?
A:
Check this code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var countries:ArrayCollection = new ArrayCollection( [
{ Country: "Romania", Romanians: 0.7, Hungarians:0.2, Germans: 0.1 }]);
]]>
</mx:Script>
<mx:Panel title="BarChart Control" layout="horizontal" color="0xffffff" borderAlpha="0.15" width="600" height="240"
paddingTop="10" paddingRight="5" paddingBottom="10" paddingLeft="5" horizontalAlign="center">
<mx:BarChart id="bar" height="100%" color="0x323232" type="stacked"
showDataTips="true" dataProvider="{countries}">
<mx:verticalAxis>
<mx:CategoryAxis categoryField="Country"/>
</mx:verticalAxis>
<mx:series>
<mx:BarSeries yField="Country" xField="Romanians" displayName="Romanians"/>
<mx:BarSeries yField="Country" xField="Hungarians" displayName="Hungarians"/>
<mx:BarSeries yField="Country" xField="Germans" displayName="Germans"/>
</mx:series>
</mx:BarChart>
<mx:Legend dataProvider="{bar}" color="0x323232"/>
</mx:Panel>
Cornel Creanga
2010-04-22 08:34:05