我有一组如下数据:
[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”属性来定义如何将每个位置的数据过滤为单独的系列,但我不知道该怎么做。 anyboy是否有任何建议或示例代码来创建此类图表? 谢谢
答案 0 :(得分: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>