9 Replies Latest reply on Nov 7, 2007 5:27 PM by J_Fraser

    Horizontal axis Labels

      Hey Everyone, I have a chart that displays financial values. Basically I return a recordset say with 365 X5 records. 5 years of days.

      On my chart though, for the 5 yr span. I only want to display 5 labels. Say 2002,2003,2004,2005,2006. Does anyone know how to accomplish this.

        • 1. Re: Horizontal axis Labels
          If anyone could shed some light on this I would greatly appreciate it...
          • 2. Re: Horizontal axis Labels
            davidmedifit Level 1
            Can you post some sample code and data for us to work with?


            1 person found this helpful
            • 3. Re: Horizontal axis Labels
              Below is my code. The cdate field is a date field and presently in my recordset I have 365 x 5yrs of records. So approx 1800 data pts. for the labels , I would just like to simply display the year once I get to that year as the label, and only display the year once. So say I have 1800 data points, I would only like to display 5 labels.

              <mx:CategoryAxis categoryField="cdate" />
              • 4. Re: Horizontal axis Labels
                davidmedifit Level 1
                I can't give you a full answer, but I can point you in the right direction

                1) Add a label function to your categoryAxis
                <mx:CategoryAxis labelfunction=test categoryField="cdate" />

                2) Code your label function in an AS block something like this:

                public function test(categoryValue:Object, previousCategoryValue:Object, axis:CategoryAxis, categoryItem:Object):String{

                if (previousCategoryValue == null){
                return categoryValue.valueOf();
                }else if (previousCategoryValue.valueOf() != categoryValue.valueOf()){
                return categoryValue.valueOf();
                return "";

                Now, the thing is, your axis category is going to be a date, right ? I'm guessing, because I haven't seen your data. So, each date will be different to the next, so you'll ALWAYS fall into the second condition of the for loop. What you'll have to do is extract the "year" value and store that in a temporary value that always stored the "Current" value, example: 2005. When you come across a year of 2006 (temp != current year value of the axis), return the NEW current year value.

                If you are including the "year" value in your datasource item, you can access that in the "categoryItem" variable. If you debug the above code, you'll get a better look at what's going on. I'm sure you'll have no problem going from here.


                • 5. Re: Horizontal axis Labels
                  Regarding your categoryItem field. How will it know the column name I am using for the year.
                  • 6. Re: Horizontal axis Labels
                    Nevermind I think I am almost there, I have it semi working but here is my problem now. Since I have over 1800 records, it now displays only the 5 yrs,etc. But since there are 1800 datapoints, the label is so tiny I cant even read it, It seems when it returns '' it actually returns a whole space which is shrinking the label tremendously..

                    • 7. Re: Horizontal axis Labels
                      davidmedifit Level 1
                      I'm not sure you'll sort that out entirely to your satisfaction, but research axis renderers in the Flex documentation. Maybe you can make the label really big.

                      <mx:Stroke color="#884422" weight="2" alpha=".75"/>
                      1 person found this helpful
                      • 8. Re: Horizontal axis Labels
                        Man I am so close, if someone could just help me this one final leg I would appreciate it greatly. The problem I am having now since I have 1800 data pts, the 4 labels I display are so small because it seems like it returns a blank space when I do return '' in my labelfunction.

                        • 9. Re: Horizontal axis Labels
                          J_Fraser Level 1
                          this may be way off track but have you tried
                          <mx:horizontalAxis >
                          <mx:DateTimeAxis dataUnits="years" />
                          1 person found this helpful