2 Replies Latest reply on Jul 20, 2010 10:50 PM by nileshnthete

    How to formate number on y axis?

    nileshnthete


      Hi,

      I have written code for formatting number on y AXIS in ###,###.## format (i.e. if no is 123456.78 then it should be formatted as 123,456.78 ).

      But I am not getting any result after compiling this can anyone help me out in this?

       

      <?xml version="1.0"?>
      <!-- charts/MultipleSeries.mxml -->
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="500"
      height="600" >
        <mx:Script>
          <![CDATA[
           import mx.charts.LinearAxis;
           import mx.controls.Alert;
           import mx.formatters.NumberFormatter;
           import mx.charts.CategoryAxis;
           
           [Bindable]
              public var numFor:NumberFormatter = new NumberFormatter();
              
              [Bindable]
              public var DECKER:Array = [
                 {date:"22-Aug-05", close:455946.12},
                 {date:"23-Aug-05", close:453054.24},
                 {date:"24-Aug-05", close:467135.54},
                 {date:"25-Aug-05", close:468845.25},
              ];
              
              public function formatNumber(categoryValue:Number, previousValue:Object, axis:LinearAxis):String
              {
               numFor.useThousandsSeparator = true;
               numFor.precision = 2;
               numFor.decimalSeparatorTo = ".";
               numFor.thousandsSeparatorTo = ",";
               Alert.show("bye");
               Alert.show("hi"+String(categoryValue));
                  return numFor.format(categoryValue);
              }
          ]]>
        </mx:Script>
      
        <mx:Panel title="Multiple Data Series" width="400" height="400">
                  
           <mx:ColumnChart id="myChart"
              dataProvider="{DECKER}"
              showDataTips="true"
              height="250"
              width="350"
           >
              <mx:horizontalAxis>
                 <mx:CategoryAxis categoryField="date" />
              </mx:horizontalAxis>
             
              <mx:series>
                 <mx:BarSeries
                   id="ls" 
                      dataProvider="{DECKER}"
                      xField="date"
                      yField="close"
                      displayName="DECKER"
                 >
                  <mx:verticalAxis >
                   <mx:LinearAxis labelFunction="formatNumber"/>
               </mx:verticalAxis>
                 </mx:BarSeries>
              </mx:series>
           </mx:ColumnChart>
           <mx:Legend dataProvider="{myChart}"/>
        </mx:Panel>
      </mx:Application>
      
      


      Nilesh Thete

        • 1. Re: How to formate number on y axis?
          rootsounds Level 4

          I'm a little confused as there are numerous simple errors thrown by the compiler on this that you really shouldn't have missed. There are a bunch of missing quotes around strings.

           

          Here is the working code:

          <?xml version="1.0"?>
          <!-- charts/MultipleSeries.mxml -->
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="500"
          height="600" >
            <mx:Script>
              <![CDATA[
               import mx.charts.LinearAxis;
               import mx.controls.Alert;
               import mx.formatters.NumberFormatter;
              
               [Bindable]
                  public var numFor:NumberFormatter = new NumberFormatter();
                 
                  [Bindable]
                  public var DECKER:Array = [
                  {date: "22-Aug-05", close: 455946.12},
                     {date: "23-Aug-05", close: 453054.24},
                     {date: "24-Aug-05", close: 467135.54},
                     {date: "25-Aug-05", close: 468845.25}
                  ];
                 
                  public function formatNumber(categoryValue:Number, previousValue:Object, axis:LinearAxis):String
                  {
                   numFor.useThousandsSeparator = true;
                   numFor.precision = 2;
                   numFor.decimalSeparatorTo = ".";
                   numFor.thousandsSeparatorTo = ",";
                   //Alert.show("bye");
                   //Alert.show("hi"+String(categoryValue));
                      return numFor.format(categoryValue);
                  }
              ]]>
            </mx:Script>
           
            <mx:Panel title="Multiple Data Series" width="400" height="400">
                     
               <mx:ColumnChart id="myChart"
                  dataProvider="{DECKER}"
                  showDataTips="true"
                  height="250"
                  width="350"
               >
                  <mx:horizontalAxis>
                     <mx:CategoryAxis categoryField="date"/>
                  </mx:horizontalAxis>
                 
                  <mx:verticalAxis >
                       <mx:LinearAxis labelFunction="formatNumber"/>
                   </mx:verticalAxis>
                
                  <mx:series>
                     <mx:ColumnSeries
                       id="ls"
                          xField="date"
                          yField="close"
                          displayName="DECKER"
                     />

                  </mx:series>
               </mx:ColumnChart>
               <mx:Legend dataProvider="{myChart}"/>
            </mx:Panel>
          </mx:Application>

          • 2. Re: How to formate number on y axis?
            nileshnthete Level 1

            Hey thanks man....

            Nilesh Thete