7 Replies Latest reply on Mar 27, 2008 11:14 PM by breez11

    Combine 2 arrayCollection values to a hAxis Label

    breez11 Level 1
      How can I get the horizontalAxis to display "Jan, 1", "Feb, 2", "Mar, 3" as labels


      ////////////////////////////////////////////
      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
      <mx:Script>
      import mx.charts.ChartItem;
      import mx.collections.ArrayCollection;
      [Bindable]
      public var expenses:ArrayCollection = new ArrayCollection([
      {Day: "1", Month: "Jan", Profit: 2000, Expenses: 1500, Amount: 450},
      {Day: "2", Month: "Feb", Profit: 1000, Expenses: 200, Amount: 600},
      {Day: "3", Month: "Mar", Profit: 1500, Expenses: 500, Amount: 300}
      ]);

      public function labelFunc(myValue:String, previousValue:String, axis:CategoryAxis):String {



      return myValue
      }

      </mx:Script>
      <mx:Panel title="Line Chart">
      <mx:LineChart id="myChart" dataProvider="{expenses}">
      <mx:horizontalAxis>
      <mx:CategoryAxis dataProvider="{expenses}" categoryField="Month" labelFunction="labelFunc"/>
      </mx:horizontalAxis>
      <mx:series>
      <mx:LineSeries yField="Profit" displayName="Profit"/>
      <mx:LineSeries yField="Expenses" displayName="Expenses"/>
      <mx:LineSeries yField="Amount" displayName="Amount"/>
      </mx:series>
      </mx:LineChart>
      <mx:Legend dataProvider="{myChart}"/>
      </mx:Panel>
      </mx:Application>
        • 1. Re: Combine 2 arrayCollection values to a hAxis Label
          Bayani Portier Level 1
          In your function,
          var returnString:String;
          returnString=expenses.Month + ", " + expenses.Day;

          Hope this helps.

          b
          • 2. Re: Combine 2 arrayCollection values to a hAxis Label
            breez11 Level 1
            I got an error
            attempting to access undefined property Month from type arrayCollection

            So I tried expenses["Month"] + ", " + expenses["Day"]

            I get no error but no chart, no nothing. I also included a Alert.show(expenses["Month"].toString()) with in that function and I don't even get the Alert.

            I wish as3 would pause all threads until the user clicked ok on a alert box
            • 3. Re: Combine 2 arrayCollection values to a hAxis Label
              breez11 Level 1
              alright so I call this function of creation complete and got a response

              public function init():void {
              Alert.show(expenses[0].Day.toString());
              }

              the issue here is I can't specify a arrayCollection index number for formatting the chart label
              • 4. Re: Combine 2 arrayCollection values to a hAxis Label
                breez11 Level 1
                another attempt which failed

                <?xml version="1.0"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
                <mx:Script>
                <![CDATA[
                import mx.controls.Alert;
                import mx.charts.ChartItem;
                import mx.collections.ArrayCollection;
                [Bindable]
                public var expenses:ArrayCollection = new ArrayCollection([
                {Day: "1", Month: "Jan", Profit: 2000, Expenses: 1500, Amount: 450},
                {Day: "2", Month: "Feb", Profit: 1000, Expenses: 200, Amount: 600},
                {Day: "3", Month: "Mar", Profit: 1500, Expenses: 500, Amount: 300}
                ]);

                public function labelFunc(myValue:String, previousValue:String, axis:CategoryAxis):String {
                var returnValue:String
                for (var i = 0; i < expenses.length; i++) {
                returnValue = expenses .Month +", " + expenses.Day;
                }
                return returnValue;
                }
                ]]>
                </mx:Script>
                <mx:Panel title="Line Chart">
                <mx:LineChart id="myChart" dataProvider="{expenses}">
                <mx:horizontalAxis>
                <mx:CategoryAxis dataProvider="{expenses}" categoryField="Month" labelFunction="labelFunc"/>
                </mx:horizontalAxis>
                <mx:series>
                <mx:LineSeries yField="Profit" displayName="Profit"/>
                <mx:LineSeries yField="Expenses" displayName="Expenses"/>
                <mx:LineSeries yField="Amount" displayName="Amount"/>
                </mx:series>
                </mx:LineChart>
                <mx:Legend dataProvider="{myChart}"/>
                </mx:Panel>
                </mx:Application>
                • 5. Re: Combine 2 arrayCollection values to a hAxis Label
                  breez11 Level 1
                  for some reason this page is stripping the "[ i ]" after expenses in my for function
                  • 6. Combine 2 arrayCollection values to a hAxis Label
                    Sreenivas R Adobe Employee
                    The following seems to give expected result:

                    <?xml version="1.0"?>
                    <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
                    <mx:Script>
                    <![CDATA[
                    import mx.controls.Alert;
                    import mx.charts.ChartItem;
                    import mx.collections.ArrayCollection;
                    [Bindable]
                    public var expenses:ArrayCollection = new ArrayCollection([
                    {Day: "1", Month: "Jan", Profit: 2000, Expenses: 1500, Amount: 450},
                    {Day: "2", Month: "Feb", Profit: 1000, Expenses: 200, Amount: 600},
                    {Day: "3", Month: "Mar", Profit: 1500, Expenses: 500, Amount: 300}
                    ]);

                    public function labelFunc(myValue:String, previousValue:String, axis:CategoryAxis, item:Object):String {
                    return item.Month + ", " + item.Day;
                    }
                    ]]>
                    </mx:Script>
                    <mx:Panel title="Line Chart">
                    <mx:LineChart id="myChart" dataProvider="{expenses}">
                    <mx:horizontalAxis>
                    <mx:CategoryAxis dataProvider="{expenses}" categoryField="Month" labelFunction="labelFunc"/>
                    </mx:horizontalAxis>
                    <mx:series>
                    <mx:LineSeries yField="Profit" displayName="Profit"/>
                    <mx:LineSeries yField="Expenses" displayName="Expenses"/>
                    <mx:LineSeries yField="Amount" displayName="Amount"/>
                    </mx:series>
                    </mx:LineChart>
                    <mx:Legend dataProvider="{myChart}"/>
                    </mx:Panel>
                    </mx:Application>
                    • 7. Re: Combine 2 arrayCollection values to a hAxis Label
                      breez11 Level 1
                      Thanks very much. Works like a charm.