1 Reply Latest reply on Feb 4, 2009 1:32 PM by ice9_us

    Help needed with datagrid

    G009
      Hey Friends

      I was wondering what is wrond with my mxml. Please let me know if you understand why mxml is not working. i have added alert button to show that for loop and for each works fine. Only problem is with init(), that too i guess because datagrid code in actionscript is not correct. please tell me correct actionscript syntaxes for creating datagird.

      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      creationComplete="create()">
      <mx:HTTPService id="head" url="header.do"
      showBusyCursor="true" result="xmlheaderHandler(event)" resultFormat="e4x"/>
      <mx:HTTPService id="data" url="test.do"
      showBusyCursor="true" result="xmlHandler(event)" resultFormat="e4x"/>
      <mx:Script>
      <![CDATA[
      import mx.containers.VBox;
      import mx.containers.HBox;
      import mx.collections.XMLListCollection;
      import mx.charts.ColumnChart;
      import mx.charts.series.ColumnSeries;
      import mx.charts.CategoryAxis;
      import mx.charts.Legend;
      import mx.rpc.events.ResultEvent;
      import mx.controls.Alert;
      import mx.controls.dataGridClasses.DataGridColumn;
      import mx.controls.DataGrid;


      [Bindable]public var expenses:XMLListCollection;
      [Bindable]public var header:XMLListCollection;

      public function xmlheaderHandler(evt:ResultEvent):void{
      // Sets testInfo's root as the student. Everything else
      // referenced in respect to this.
      var list:XMLList = evt.result..HEADER;
      header = new XMLListCollection(list);

      }

      public function xmlHandler(evt:ResultEvent):void{
      // Sets testInfo's root as the student. Everything else
      // referenced in respect to this.
      var list:XMLList = evt.result..VALUES;
      expenses = new XMLListCollection(list);

      }

      //Chart variables
      public var myChart1:ColumnChart;
      public var myChart2:ColumnChart;
      public var series1:ColumnSeries;
      public var series2:ColumnSeries;
      public var legend1:Legend;
      public var legend2:Legend;

      //Grid variables
      public var dg:DataGrid = new DataGrid();
      public var dgc:DataGridColumn = new DataGridColumn();

      public function create():void {
      head.send();
      data.send();
      }


      public function showme():void {
      var i:int;
      var value:String;
      for(i=0;i<3;i++)
      {
      for each(var item5:XML in header){
      value = value +""+ item5..VALUE .toString();
      }

      }


      Alert.show(value);

      }

      public function init():void {
      var i:int;
      var max:int;

      for each(var item6:XML in header){
      max = Number(item6..COUNT[0]);
      }


      for(i=0;i<max;i++)
      {
      for each(var item5:XML in header){
      dgc.dataField = item5..ID
      .toString();
      dgc.headerText = item5..VALUE .toString();
      }

      }

      dg.dataProvider="expenses";
      dg.width = 500;
      dg.height = 500;
      dg.columns = new Array(dgc);

      //VBox for Chart and legend
      var hbox:HBox = new HBox();

      var vbox3:VBox = new VBox();
      vbox3.addChild(dg);

      hbox.addChild(vbox3);
      // Attach chart and legend to the display list.
      p1.addChild(hbox);

      }
      ]]>
      </mx:Script>
      <mx:Panel id="p1" title="Column Chart Created in ActionScript">
      <mx:HBox>
      <mx:Button id="bt1" label="Alert" click="showme()"/>
      <mx:Button id="bt2" label="Chart" click="init()"/>
      <mx:Button id="bt3" label="Grid"/>
      </mx:HBox>
      </mx:Panel>
      </mx:Application>
      .......................................................................................... ..........................................................................
      header.xml
      <?xml version="1.0" encoding="utf-8"?>
      <XMLDocument>
      <HEADER>
      <COUNT>3</COUNT>
      <COLUMN><ID>c10</ID><VALUE>Bill Month</VALUE></COLUMN>
      <COLUMN><ID>c11</ID><VALUE>Merchant Amount Average</VALUE></COLUMN>
      <COLUMN><ID>c12</ID><VALUE>Account Count</VALUE></COLUMN>
      </HEADER>
      </XMLDocument>
      .......................................................................................... ............................................................................
      test.xml
      <?xml version="1.0" encoding="utf-8"?>
      <XMLDocument>
      <VALUES><c10>Nov 2005</c10><c11>205.2052</c11><c12>463290.84</c12></VALUES>
      <VALUES><c10>Dec 2005</c10><c11>241.817</c11><c12>465985.98</c12></VALUES>
      <VALUES><c10>Jan 2006</c10><c11>231.0464</c11><c12>468981.96</c12></VALUES>
      </XMLDocument>


      Thanks in advance
        • 1. Re: Help needed with datagrid
          ice9_us Level 1
          is this what you want?



          <?xml version="1.0"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="create()">

          <mx:HTTPService id="head" url="c:\testfromweb.xml" showBusyCursor="true" result="xmlheaderHandler(event)" resultFormat="e4x"/>

          <mx:HTTPService id="data" url="c:\test2fromweb.xml" showBusyCursor="true" result="xmlHandler(event)" resultFormat="e4x"/>
          <mx:Script>
          <![CDATA[
          import mx.containers.VBox;
          import mx.containers.HBox;
          import mx.collections.XMLListCollection;
          import mx.charts.ColumnChart;
          import mx.charts.series.ColumnSeries;
          import mx.charts.CategoryAxis;
          import mx.charts.Legend;
          import mx.rpc.events.ResultEvent;
          import mx.controls.Alert;
          import mx.controls.dataGridClasses.DataGridColumn;
          import mx.controls.DataGrid;


          [Bindable]
          public var expenses:XMLListCollection;
          [Bindable]
          public var header:XMLListCollection;

          public function xmlheaderHandler(evt:ResultEvent):void{
          // Sets testInfo's root as the student. Everything else
          // referenced in respect to this.
          var list:XMLList = evt.result..HEADER;
          header = new XMLListCollection(list);

          }

          public function xmlHandler(evt:ResultEvent):void{
          // Sets testInfo's root as the student. Everything else
          // referenced in respect to this.
          var list:XMLList = evt.result..VALUES;
          expenses = new XMLListCollection(list);

          }

          //Chart variables
          public var myChart1:ColumnChart;
          public var myChart2:ColumnChart;
          public var series1:ColumnSeries;
          public var series2:ColumnSeries;
          public var legend1:Legend;
          public var legend2:Legend;

          //Grid variables
          public var dg:DataGrid = new DataGrid();
          public var dgc:DataGridColumn = new DataGridColumn();

          public function create():void {
          head.send();
          data.send();
          }


          public function showme():void {
          var i:int;
          var value:String;
          for(i=0;i<3;i++)
          {
          for each(var item5:XML in header){
          value = value +""+ item5..VALUE.toString();
          }

          }


          Alert.show(value);

          }

          public function init():void {
          var i:int;
          var max:int;

          for each(var item6:XML in header){
          max = Number(item6..COUNT[0]);
          }


          for(i=0;i<max;i++)
          {
          for each(var item5:XML in header){
          dgc.dataField = item5..ID.toString();
          dgc.headerText = item5..VALUE.toString();
          }

          }

          dg.dataProvider = expenses;
          dg.width = 500;
          dg.height = 500;
          dg.columns = new Array(dgc);

          //VBox for Chart and legend
          var hbox:HBox = new HBox();

          var vbox3:VBox = new VBox();
          vbox3.addChild(dg);

          hbox.addChild(vbox3);
          // Attach chart and legend to the display list.
          p1.addChild(hbox);

          }
          ]]>
          </mx:Script>
          <mx:Panel id="p1" title="Column Chart Created in ActionScript">
          <mx:HBox>
          <mx:Button id="bt1" label="Alert" click="showme()"/>
          <mx:Button id="bt2" label="Chart" click="init()"/>
          <mx:Button id="bt3" label="Grid"/>
          </mx:HBox>
          </mx:Panel>
          </mx:Application>