【问题标题】:Building stack bar chart from objects array in flex从flex中的对象数组构建堆栈条形图
【发布时间】:2010-04-21 15:52:48
【问题描述】:

我有一个动态的ArrayCollection,它将包含未知数量的MyObj类型的对象:

class MyObj
{
   type:String
   value:long
}

每个MyObj 对象都有不同的type 值。

如何从这个数组构建单个堆叠条,其中堆叠条的每个部分代表MyObj 的一个对象(代表type),它的长度是value

【问题讨论】:

    标签: apache-flex charts bar-chart


    【解决方案1】:

    检查此代码:

    <?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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-08
      • 1970-01-01
      • 1970-01-01
      • 2018-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多