我有一个动态ArrayCollection
,其中包含未知数量的MyObj
类型的对象:
class MyObj
{
type:String
value:long
}
每个MyObj
对象都有不同的type
值。
如何从此数组构建单个堆叠条形图,其中堆积条形的每个部分代表MyObj
的对象(代表type
),其长度为value
?
答案 0 :(得分:0)
检查此代码:
<?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>