0 Replies Latest reply on May 9, 2011 6:32 AM by vantur2323

    Webservice data with Chart

    vantur2323

      Hello Guys,

       

      i have a little Problem with my Webservice data chart. I want to show the data I recived from webservice in a column chart. But i got some
      problems and the chart isnt shown.

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application
          xmlns:fx="http://ns.adobe.com/mxml/2009"
                             xmlns:s="library://ns.adobe.com/flex/spark"
                             xmlns:mx="library://ns.adobe.com/flex/mx">
         
          <fx:Script>
              <![CDATA[
                  import mx.charts.ChartItem;
                  import mx.collections.ArrayCollection;
                  import mx.controls.Alert;
                  import mx.events.FlexEvent;
                  import mx.graphics.IFill;
                  import mx.graphics.SolidColor;
                  import mx.rpc.events.FaultEvent;
                  import mx.rpc.events.ResultEvent;
                  import mx.rpc.soap.LoadEvent;

       

                  private var partiesData:ArrayCollection;
                  private var statesData:ArrayCollection;
                  private var federalResultsData:ArrayCollection;
                 
                  [Bindable]private var parteien:ArrayCollection = new ArrayCollection( [
                      { Partei: "", Stimmen: 0, Prozent:0},
                      { Partei: "", Stimmen: 0, Prozent:0},
                      { Partei: "", Stimmen: 0, Prozent:0},
                      { Partei: "", Stimmen: 0, Prozent:0},
                      { Partei: "", Stimmen: 0, Prozent:0},
                      { Partei: "", Stimmen: 0, Prozent:0}
                  ]);
                 
                  /*[Bindable]private var parteien:ArrayCollection = new ArrayCollection( [
                      { Partei: "CDU\\CSU", Stimmen: 14658515, Prozent:33.7978146},
                      { Partei: "SPD", Stimmen: 9990488, Prozent:23.0348483},
                      { Partei: "FDP", Stimmen: 6316080, Prozent:14.5628467},
                      { Partei: "Die Linke", Stimmen: 5155933, Prozent:11.8879206},
                      { Partei: "Grüne", Stimmen: 4643272, Prozent:10.70589},
                      { Partei: "Sonstige", Stimmen: 2606902, Prozent:6.01067636486}
                  ]);*/
                 
                 
                 
                  public function electionService_loadHandler(event:LoadEvent):void
                  {
                      electionService.Parties.send();
                      electionService.TotalVotes.send();
                      electionService.States.send();
                      electionService.FederalResults.send();

       

                  }

       

                  public function electionService_faultHandler(event:FaultEvent):void
                  {
                      Alert.show("Fehler beim Laden der Remote-Daten.");
                  }

       

                 
                  public function federalResultsHandler(event:ResultEvent):void
                  {
                      federalResultsData=event.result as ArrayCollection;
                      trace("test");

       


                          var index: int = 0;
                          var prozent_ges:Number = 0.0;
                          var stimmen_ges:Number = 0.0;
                          var array:Array = new Array();
                          var array2:Array = new Array();
                          var array3:Array = new Array();
                         
                         
                         
                          for each (var p:Object in federalResultsData)
                          {
                             
                              array[index]=(p.Party);
                              array2[index]=(p.Votes);
                              array3[index]=(p.Percentage);
                             
                             
                              index++
                          }
                          for(var i:int=0;i<5;i++)
                          {   
                              parteien[i].Partei= array[i];
         
         
                              parteien[i].Stimmen= array2[i];
                     
                             
                              parteien[i].Prozent= (array3[i]*100);
         
                          }   
                         
                          for(var j:int=6;j<array3.length;j++)
                          {
                             
                             
                              prozent_ges += array3[j];
                              stimmen_ges += array2[j];
         
                          }
                          parteien[0].Partei += "\\CSU";
                          parteien[0].Stimmen += array2[5];
                          parteien[0].Prozent += (array3[5]*100);
                         
                          parteien[5].Partei = "Sonstige";
                          parteien[5].Stimmen = stimmen_ges;
                          parteien[5].Prozent = prozent_ges;
                         
         
                          trace("p "+parteien[0].Partei);
                          trace("p "+parteien[0].Stimmen);
                          trace("p "+parteien[0].Prozent);
                         
                          trace("p "+parteien[1].Partei);
                          trace("p "+parteien[1].Stimmen);
                          trace("p "+parteien[1].Prozent);
                         
                          trace("p "+parteien[2].Partei);
                          trace("p "+parteien[2].Stimmen);
                          trace("p "+parteien[2].Prozent);
                         
                          trace("p "+parteien[3].Partei);
                          trace("p "+parteien[3].Stimmen);
                          trace("p "+parteien[3].Prozent);
                         
                          trace("p "+parteien[4].Partei);
                          trace("p "+parteien[4].Stimmen);
                          trace("p "+parteien[4].Prozent);
                         
                          trace("p "+parteien[5].Partei);
                          trace("p "+parteien[5].Stimmen);
                          trace("p "+parteien[5].Prozent);

       

                          column.dataProvider = event.result as ArrayCollection
                          column.executeBindings(true);
                         
                  }
                 
                  public function voteClickHandler(event:MouseEvent):void
                  {
                      if (totalVotesArrived)
                      {
                          Alert.show(electionService.TotalVotes.lastResult);
                      }
                      else
                      {
                          Alert.show("Daten sind noch nicht da...");
                      }
                  }
                 
                  public function totalVotesHandler(event:ResultEvent):void
                  {
                      totalVotesArrived=true;
                  }
                 
                  public function stateHandler (event:ResultEvent):void
                  {
                      statesData = event.result as ArrayCollection;
                      statesArrived=true;
                  }
                 
                  public function stateClickHandler (event:MouseEvent):void
                  {
                      if(statesArrived)
                      {   
                          Alert.show(statesData[1].Name);
                      }
                      else
                      {
                          Alert.show("Daten sind noch nicht da...");
                      }   
                     
                  }
                 
                  private function fillFunction (item:ChartItem, index:Number):IFill
                  { 

       

                      if(item.item.Partei == "SPD")
                      {
                          return new SolidColor(0xF20313,0.8);
                      }
                      if(item.item.Partei == "FDP")
                      {
                          return new SolidColor(0xFFFF1E,0.8);
                      }   
                      if(item.item.Partei == "Die Linke")
                      {
                          return new SolidColor(0xEF3CE3,0.8);
                      }   
                      if(item.item.Partei == "Grüne")
                      {
                          return new SolidColor(0x33B72A,0.8);
                      }   
                      if(item.item.Partei == "Sonstige")
                      {
                          return new SolidColor(0xD0CDCF,0.8);
                      }   
                      else
                      {
                          return new SolidColor(0x000000,0.8);
                      }

       

                  }

       


              ]]>
          </fx:Script>

       

          <fx:Declarations>
             
              <fx:Boolean id="totalVotesArrived"/>
              <fx:Boolean id="statesArrived"/>
              <fx:Boolean id="partiesArrived"/>

       

              <s:WebService id="electionService"
                            wsdl="http://gamepc06.fh-trier.de:8080/ElectionResults.asmx?wsdl"
                            fault="electionService_faultHandler(event)"
                            load="electionService_loadHandler(event)">

       

       

       

                  <s:operation name="TotalVotes"            
                               result="totalVotesHandler(event)"/>
                  <s:operation name="States"            
                               result="stateHandler(event)"/>
                  <s:operation name="FederalResults"            
                               result="federalResultsHandler(event)"/>
              </s:WebService>

       

         
          </fx:Declarations>
         
          <!--<s:Button id = "tvb"  click="voteClickHandler(event)" label="TotalVotes" x="146" y="56"/>
          <s:Button id = "stb"  click="stateClickHandler(event)" label="States" x="360" y="104"/>
          <mx:Button id ="tv"   click="voteClickHandler(event)"  label ="Total Votes" x="360" y="133" />
          <s:TextArea id ="txt" x="146" y="104"/>-->
         
         
         
          <s:Panel title="Balkendiagramm" width="874" height="100%"
                   color="0x000000"
                   borderAlpha="0.15" x="496" y="0">
             
              <s:layout>
                  <s:HorizontalLayout horizontalAlign="center"
                                      paddingLeft="10" paddingRight="10"
                                      paddingTop="10" paddingBottom="10"/>
              </s:layout>
             
              <mx:ColumnChart id="column" height="100%" color="0x000000"
                              showDataTips="true"  width="782">
             
                 
                  <mx:horizontalAxis >
                      <mx:CategoryAxis  categoryField="Partei"   />
                  </mx:horizontalAxis>
                 
                  <mx:series>
                     
                      <mx:ColumnSeries xField="Partei" yField="Prozent" displayName="" fillFunction="{fillFunction}" />

       

                  </mx:series>
              </mx:ColumnChart>

       

             
          </s:Panel>
      </s:Application>

       

      What im doing is, I crating an ArrayCollection and inizalize it with 0. So, when my webservice start the Methode federalResultsHandler
      writes the data in my ArrayCollection and my chart should show this data. But the chart shows nothing, only if I use the "filled" example.
      The only think what happens is, if i declare the dataprovieder in the <mx:ColumnChart ist resize the grid on the left to 34 but not the columns.

       

      Sorry for my english, I`m from Germany and my used webservice too. But I hope you can help me anyhow.