4 Replies Latest reply on Jun 27, 2008 8:30 AM by ntsiii

    pie chart using httpservice

    FlexPrashant Level 1
      hello guys i am using a httpservice for giving dataprovider to pie chart ..When this service return a single record ,pie chart do not show anything instead of showing 100%...
      problem occurs when my service return this..
      <?rss version="2.0"?>

      <data>

      <SalesReport>
      <status>Assigned</status>
      <inquiry>22</inquiry>
      </SalesReport>
      </data>
      otherwise it's work fine.......if it return

      <?rss version="2.0"?>

      <data>

      <SalesReport>
      <status>Assigned</status>
      <inquiry>22</inquiry>
      </SalesReport>

      <SalesReport>
      <status>New</status>
      <inquiry>12</inquiry>
      </SalesReport>
      </data>


      Here is my code .... Please help me .....

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      backgroundGradientColors="[#ffffff, #808080]" creationComplete="init();">

      <mx:Style>
      <mx:Script >
      <![CDATA[
      import mx.binding.utils.BindingUtils;
      import mx.rpc.events.ResultEvent;
      import mx.collections.ArrayCollection;
      import mx.controls.Alert;
      [Bindable]
      public var reportData10A:ArrayCollection;
      [Bindable]
      public var reportData10A1:ArrayCollection;
      [Bindable]
      public var comboData10A:ArrayCollection;
      public var fromMonth10A:Number;

      public var techID:Number;
      public var salesPerson10A:String;
      [Bindable]
      public var comboData10A1:ArrayCollection;

      public function mytest10A():void
      {
      salesPerson10A = salesPesronCombo.selectedLabel.toString();
      var salesPID:Number = mytest10A2(salesPerson10A);
      fromMonth10A = monthFromCombo10A.selectedIndex + 1 ;
      techID = TechnologyCombo.selectedIndex+1;

      var str:String =" http://reena-new:3021/reports/specperson_spectech?year="+yearCombo10A.selectedLabel+"&pers on="+salesPID+"&month="+fromMonth10A+"&techid="+techID;
      Alert.show(str);
      reportService10A.url=" http://reena-new:3021/reports/specperson_spectech?year="+yearCombo10A.selectedLabel+"&pers on="+salesPID+"&month="+fromMonth10A+"&techid="+techID;
      reportService10A.send();
      reportData10A = new ArrayCollection();
      reportData10A = reportService10A.lastResult.data.SalesReport;

      }

      public var i:Number;
      public var salesPersonId:Number;

      public function mytest10A2(str:String):Number
      {

      for(i=0;i<comboData10A.length;i++)
      {
      if(comboData10A.name==str)
      {
      salesPersonId = Number(comboData10A.id);
      break;
      }
      }
      return salesPersonId;
      }





      public function init():void
      {
      this.comboData10A = new ArrayCollection();
      this.reportData10A = new ArrayCollection();
      this.comboData10A1 = new ArrayCollection();

      //reportService10A.url=" http://reena-new:3021/reports/specperson_spectech?year=2008&person=1&month=04&techid=1";
      reportService10A.url="my.xml";
      reportService10A.send();

      comboService10A.send();
      ComboService10A1.send();

      }

      public function getData10A(event:ResultEvent):void
      {
      reportData10A = new ArrayCollection();
      reportData10A= event.result.data.SalesReport;
      //Alert.show(reportData10A.length.toString());

      }





      public function getComboData10A(event:ResultEvent):void
      {
      comboData10A = new ArrayCollection();
      comboData10A = event.result.data.SalesPerson;
      }



      public function getComboData10A1(event:ResultEvent):void
      {
      comboData10A1 = new ArrayCollection();
      comboData10A1 = event.result.data.technology;
      }


      ]]>
      </mx:Script>

      <mx:HTTPService id="reportService10A" showBusyCursor="true"

      result="getData10A(event);" />


      <mx:HTTPService id="ComboService10A1" showBusyCursor="true"
      url=" http://reena-new:3021/reports/techlist" result="getComboData10A1(event)" />


      <mx:HTTPService id="comboService10A" showBusyCursor="true"

      result="getComboData10A(event);" url=" http://reena-new:3021/reports/personlist"/>

      <mx:Canvas id="report10A" height="75%" width="70%" x="0" y="100"
      verticalScrollPolicy="off" horizontalScrollPolicy="off">

      <mx:PieChart id="pie10A" x="0" y="25" width="350"
      dataProvider="{reportData10A}"
      showDataTips="true"
      >
      <mx:series>
      <mx:PieSeries
      field="inquiry"
      labelPosition="callout"
      nameField="status"
      />
      </mx:series>

      </mx:PieChart>
      <mx:Legend dataProvider="{pie10A}" />

      <!-- <mx:PieChart id="pie10A1" x="365" y="25" width="350"
      dataProvider="{reportData10A1}"
      showDataTips="true"
      >
      <mx:series>
      <mx:PieSeries
      field="inquiry"
      nameField="name"
      labelPosition="callout"

      />
      </mx:series>

      </mx:PieChart>
      <mx:Legend dataProvider="{pie10A1}" x="350" /> -->


      </mx:Canvas>
      <mx:Canvas x="0" y="0" height="90" width="100%">

      <mx:HBox y="30" id="combo10A" x="0" >

      <mx:Label text="Sales Person" fontSize="12"/>
      <mx:ComboBox width="100" id="salesPesronCombo" change="mytest10A()();"
      dataProvider="{comboData10A}" labelField="name">

      </mx:ComboBox>


      <mx:Label text="Technology" fontSize="12"/>
      <mx:ComboBox width="100" id="TechnologyCombo" change="mytest10A()();"
      dataProvider="{comboData10A1}" labelField="name">

      </mx:ComboBox>



        • 1. Re: pie chart using httpservice
          matthew horn Level 3
          When I simplify your code and use the data in an mx:Model, a pie with a single slice works fine:

          <?xml version="1.0"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
          <mx:Model id="myModel">
          <data>
          <SalesReport>
          <status>Assigned</status>
          <inquiry>22</inquiry>
          </SalesReport>
          </data>
          </mx:Model>
          <mx:PieChart id="myChart"
          dataProvider="{myModel.SalesReport}"
          >
          <mx:series>
          <mx:PieSeries
          field="inquiry"
          nameField="status"
          />
          </mx:series>
          </mx:PieChart>
          </mx:Application>

          I have to assume that the issue you're having has to do with the way you're building your array collections. Sorry I cant be more help, but I had a hard time following it.

          matt horn
          flex docs
          • 2. Re: pie chart using httpservice
            ntsiii Level 3
            With the default resultFormat on the HTTPService, flex converts your xml into a nested object structure.

            Presumably, this is supposed to return an array:
            event.result.data.technology;

            However, the flash Player is unable to differentiate between an array with a single element and an object, so fails to display the single element.

            You can use ArrayUtil.toArray() to fix this. Also, you are not really doing your ArrayCollection correctly. Just do:
            public function getComboData10A1(event:ResultEvent):void
            {
            comboData10A1 = new ArrayCollection(event.result.data.technology);
            }

            However, that default conversion has many drawbacks and I advise using resultFormat="e4x" and working with real XML.

            Finally, by using AsyncToken, you can use a single HttpService instance and a single result handler for all of your data service calls.

            Tracy
            1 person found this helpful
            • 3. Re: pie chart using httpservice
              FlexPrashant Level 1
              this is the answer ................

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
              backgroundGradientColors="[#ffffff, #808080]" creationComplete="init();">



              <mx:Script>
              <![CDATA[
              import mx.binding.utils.BindingUtils;
              import mx.controls.Alert;
              import mx.rpc.events.ResultEvent;
              import mx.collections.ArrayCollection;

              [Bindable]
              public var xmlResult:XML;

              public function init():void
              {
              Alert.show("we are here");
              myService.url="my.xml";
              myService.send();
              }


              public function onResult(event:ResultEvent):void
              {
              xmlResult = new XML
              xmlResult = XML(event.result);
              Alert.show(xmlResult);
              }



              ]]>
              </mx:Script>

              <mx:HTTPService id="myService" url="my.xml" result="onResult(event)"
              resultFormat="e4x"/>

              <mx:PieChart id="pie10A" x="0" y="25" width="350"
              dataProvider="{xmlResult.child('SalesReport')}"
              showDataTips="true"
              >
              <mx:series>
              <mx:PieSeries
              field="inquiry"
              labelPosition="callout"
              nameField="status"
              />
              </mx:series>

              </mx:PieChart>
              <mx:Legend dataProvider="{pie10A}" />

              </mx:Application>

              Thanks
              • 4. Re: pie chart using httpservice
                ntsiii Level 3
                Very good. That is exactly how I do it.

                You can remove this line:
                xmlResult = new XML; //It is useless.

                This, XML(event.result), LOOKS like a constructor(an a cast!), but it is really a "top-level" function.

                Tracy