I am trying to provide my own labelFunction for a CategoryAxis programatically but am completely stumped. The regular way is to do it in your MXML file, but I want to do it in my Actionscript file.
The regular way of doing it is:
<mx:Script> <![CDATA[ private function categoryAxis_labelFunc(item:Object, prevValue:Object, axis:CategoryAxis, categoryItem:Object):String { return 'Some String'; } ]]> </mx:Script> <mx:CategoryAxis labelFunction='categoryAxis_labelFunc' />
But I want to achieve the same thing in my subclass of CategoryAxis, something like:
public class FauxDateAxis extends CategoryAxis { public function FauxDateAxis() { super(); labelFunction = categoryAxis_labelFunc // Doesn't work of course. } private function categoryAxis_labelFunc(item:Object, prevValue:Object, axis:CategoryAxis, categoryItem:Object):String { return 'Another String'; } }
Well, I’m baffled by your problem, because it works absolutely fine for me.
I took the example application for CategoryAxis from the Adobe Flex site: http://livedocs.adobe.com/flex/3/langref/index.html?mx/charts/CategoryAxis.html&mx/charts/class-list.html, added your code verbatim (well except for adding package and import statments), and it worked just like you want it to.
In the example, I modified the line
to read
and it displayed ‘Another String’ at the base of each column.
I’m using Flex 3, if that matters.
Good Luck, Randy Stegbauer