3

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";
    }   

}

3 Answers 3

2

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

<mx:CategoryAxis id="haxis" categoryField="Date" title="Date"/>

to read

<local:FauxDateAxis id="haxis" categoryField="Date" title="Date"/>

and it displayed "Another String" at the base of each column.

I'm using Flex 3, if that matters.

Good Luck, Randy Stegbauer

Sign up to request clarification or add additional context in comments.

Comments

1

This question got me curious, so I went off and tried it.

The labelFunction on CategoryAxis has a slightly different signature than what I am seeing here. For me, this is what works:

function(item:Object, field:String, index:int, pct:Number)

I am not a Flex charts wizard, so perhaps you know something I don't, but when I use that signature in this matter,

public function FauxDateAxis() {
    super();
    labelFunction = function(item:Object, field:String, index:int, pct:Number) {
       return "string";
    }
}

It works for me in Flex 3 Pro.

I see that the code sample you provided looks a lot like http://blog.flexexamples.com/2007/11/16/creating-a-custom-label-function-on-a-flex-linechart-controls-category-axis/ (I tried to see if I could find an example of the signature you provided). I see other people using this signature too.

This isn't much of an answer; I don't recall this part of the charts API changing between Flex 2 and Flex 3, but maybe this post helps you with your problem.

1 Comment

The signature shown is exactly what is specified in the CategoryAxis documentation livedocs.adobe.com/flex/3/langref/index.html?mx/charts/…. Randy Stegbauer
0

Just I though, I don't think it will make a difference, but maybe change your label function scope to protected rather than private???

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.