开发者

Flex Chart Legend - how to get fine grained programmatic control?

开发者 https://www.devze.com 2023-01-16 04:21 出处:网络
I am looking to get access to individual legend items in actionscript (a Legend Item being the label and coloured block identifying a chart series). Does anyone know of a property of the Legend or Cha

I am looking to get access to individual legend items in actionscript (a Legend Item being the label and coloured block identifying a chart series). Does anyone know of a property of the Legend or Chart that gives access to all of the currently displayed LegendItems in a Legend?

I know this is possible by using LegendMouseEvents, as the event开发者_如何学运维s give access to the LegendItem that has been clicked/rolled over ect. However, I cannot rely on an event in this case.

My last resort is to hack up a custom legend, but this will take time (which I don't particularly have) so I just thought I would appeal to the SO community first!

Thanks guys


A legend is a container, so you should be able to do as shown in the code below:

var currentLegendItem:LegendItem;

for (var i:int = 0; i < legend.numChildren; i++) {
currentLegendItem = LegendItem(legend.getChildAt(i));
}


I tried the solution proposed by Double but, for some reason, it didn't work (though it really should have). I'll have to see about trying to get it to work later. Thought I'd post this alternative solution in case anyone else is having the same trouble.

I managed to find another solution (though I'm not sure if it would help the OP in their situation). I only needed to influence my legendItems on creation so performed an action on the legend's childAdd event and did what I needed to do to the legendItem then.

private function legendItemAdded(event:ChildExistenceChangedEvent):void {
   var legendItem:LegendItem = event.relatedObject as LegendItem;

   // do what you want with it
}

.........

<mx:Legend id="myLegend"
dataProvider="{myDP}"
borderStyle="solid"
stroke=""
borderThickness="0"
top="0" bottom="20"
childAdd="legendItemAdded(event)"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号