1 Reply Latest reply on Oct 25, 2007 2:53 PM by Gregory Lafrance

    ArrayCollection in PieChart`

    kilyas2007 Level 1
      I am working on a pieChart

      <mx:PieChart id="pie" dataProvider="{expenses}" showDataTips="true" width="100%" height="100%">
      <mx:series>
      <mx:PieSeries field="Amount"
      labelPosition="callout"/>
      </mx:series>
      </mx:PieChart>

      If here I define expenses as follows:-
      public var expenses:ArrayCollection = new ArrayCollection([
      {Expense: "Taxes", Amount: 2000},
      {Expense: "Rent", Amount: 1000},
      {Expense: "Bills", Amount: 100},
      {Expense: "Car", Amount: 450},
      {Expense: "Gas", Amount: 100},
      {Expense: "Food", Amount: 200}
      ]);

      It works,
      if However Instead I replace it with the code

      package
      {
      public class ExpenseItem
      {
      var Expense:String;
      var Amount:Number;

      public function RiskAggregationItem( texp:String, tam:uint){
      Expense=texp;
      Amount=tam;
      }
      }
      }

      and

      var expenses:ArrayCollection = new ArrayCollection();

      expenses.addItem(new ExpenseItem("Taxes", 2000));
      expenses.addItem(new ExpenseItem("Khurram", 300));

      It gives me the error
      ReferenceError: Error #1069: Property Amount not found

      Anyadvice?
        • 1. Re: ArrayCollection in PieChart`
          Gregory Lafrance Level 6
          I think Expense and Amount must be made public. This code works:

          package {
          public class ExpenseItem {
          public var Expense:String;
          public var Amount:Number;

          public function ExpenseItem( texp:String, tam:uint){
          Expense=texp;
          Amount=tam;
          }
          }
          }

          <?xml version="1.0"?>
          <!-- dpcontrols/ListDataProvider.mxml -->
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" creationComplete="init()">
          <mx:Script>
          <![CDATA[
          import mx.collections.ArrayCollection;

          [Bindable]
          public var expenses:ArrayCollection = new ArrayCollection();

          public function init():void{
          expenses.addItem(new ExpenseItem("Taxes", 2000));
          expenses.addItem(new ExpenseItem("Khurram", 300));
          }

          [Bindable]
          public var expenses2:ArrayCollection = new ArrayCollection([
          {Expense: "Taxes", Amount: 2000},
          {Expense: "Rent", Amount: 1000},
          {Expense: "Bills", Amount: 100},
          {Expense: "Car", Amount: 450},
          {Expense: "Gas", Amount: 100},
          {Expense: "Food", Amount: 200}
          ]);
          ]]>
          </mx:Script>

          <mx:PieChart id="pie" dataProvider="{expenses}" showDataTips="true" width="100%" height="100%">
          <mx:series>
          <mx:PieSeries field="Amount"
          labelPosition="callout"/>
          </mx:series>
          </mx:PieChart>
          </mx:Application>