0

我有一组数据,如下所示:

        [Bindable]
    public var Loc:ArrayCollection = new ArrayCollection([
        {date:"2002", close:41.87, loc: "Location 01"},
        {date:"2003", close:45.74, loc: "Location 01"},
        {date:"2004", close:42.77, loc: "Location 01"},
        {date:"2005", close:48.06, loc: "Location 01"},
        {date:"2006", close:48.06, loc: "Location 01"},
        {date:"2002", close:157.59, loc: "Location 02"},
        {date:"2003", close:160.3, loc: "Location 02"},
        {date:"2004", close:150.71, loc: "Location 02"},
        {date:"2005", close:156.88, loc: "Location 02"},
    ]);

我想创建一个如下所示的图表,其中每个位置以不同的颜色显示并按年份分组: 在此处输入图像描述

我在想我必须使用“mx:ColumnSeries”标签并使用它的“filterFunction”属性来定义如何将每个位置的数据过滤为一个单独的系列,但我不知道该怎么做。有没有任何男孩有任何建议或示例代码来创建这样的图表?谢谢

4

1 回答 1

1

这里有一个例子:

private function filterSeries1(cache:Array):Array
{
    var filteredCache:Array = [];
    for (var i:int = 0; i < cache.length; i++)
    {
        var item:ColumnSeriesItem = ColumnSeriesItem(cache[i]);
        if(item.item.loc == "Location 01")
            filteredCache.push(item);
    }
    return filteredCache;
}

private function filterSeries2(cache:Array):Array
{
    var filteredCache:Array = [];
    for (var i:int = 0; i < cache.length; i++)
    {
        var item:ColumnSeriesItem = ColumnSeriesItem(cache[i]);
        if(item.item.loc == "Location 02")
            filteredCache.push(item);
    }
    return filteredCache;
}

和:

<mx:series>
    <mx:ColumnSeries yField="close" xField="date"
                     labelPosition="outside"
                     filterFunction="{filterSeries1}"/>
    <mx:ColumnSeries yField="close" xField="date"
                     labelPosition="outside"
                     filterFunction="{filterSeries2}"/>
</mx:series>
于 2013-06-25T15:14:50.483 回答