0 Replies Latest reply on May 3, 2009 12:08 AM by pablo89

    Problems between charts in differents modules - Flex 3

    pablo89

      Hi all! Im new here, and also Im new in Flex (and in english, so Im new in everything jajaja) I have a big problem, I've made a simple application with modules. The main application call a module, in that module there is a "submodule" that creates charts (colum, line or pie) these charts are created with ActionScript; there is a linkbutton that loads a new module, this module creates a pie chart, but then appears this error: TypeError: Error #1034: Type Coercion failed: cannot convert mx.graphics::Stroke@1377e181 to mx.graphics.IStroke. The charts separated works fine, but here no! I have searched all the web but I didnt find a solution. I hope you can help me please!! and sorry for my english

       

      This is the code of the chart that is created with AS

          <mx:Script>
              <![CDATA[
                  import mx.rpc.events.ResultEvent;
                  import mx.events.ListEvent;
                  import mx.controls.Alert;       
                 
                  //Charts
                  import mx.collections.*;
                  import mx.charts.*;
                  import mx.charts.series.*;       
                  import mx.charts.series.LineSeries;
                  import mx.charts.renderers.*;
                  import mx.charts.events.*;
         
                  [Bindable]public var datagraf:XMLList; 
                  [Bindable]public var tipo:int;

       

                  //Pie
                  public var pastel:PieChart;
                  public var pstserie:PieSeries;
                  public var pstleg:Legend;
                 
                  //Line
                  public var linea:LineChart;
                  public var lnserie:LineSeries;
                 
                  //Column
                  public var columna:ColumnChart;
                  public var clmserie:ColumnSeries;

       

                  //Cats
                  public var vAxis:CategoryAxis;
                 
                  public function cargaDataIni(event:ResultEvent):void{
                      var grafico:int=event.result.grafico;
                      tipo=event.result.tipo;
                     
                      var params:Object ={};
                      params["id_cliente"]=parentApplication.idUser;
                      params["tipo"]=grafico;
                      grafBarraHT.send(params);
                  }
                 
                  public function resultGraf(event:ResultEvent):void{
                      datagraf=event.result.dato;
                     
                      var miserie:Array=new Array();
                      if(tipo==0){
                          //Crea el grafico de pastel
                          pastel=new PieChart;
                          pastel.id="graficoinicial";
                          pastel.showDataTips=true;
                          pastel.dataProvider=datagraf;
                          pastel.width=384;
                          pastel.height=157;
                          pastel.x=0;
                          pastel.y=0;
                         
                          //Crea la serie
                          pstserie=new PieSeries;
                          pstserie.field="valor";
                          pstserie.nameField="campo";
                          pstserie.displayName="Series 1";
                          miserie.push(pstserie);
                         
                          //Agrega la serie
                          pastel.series=miserie;
                         
                          //Crea la leyenda
                          pstleg=new Legend;
                          pstleg.dataProvider=pastel;
                         
                          //Agrega el grafico al modulo
                          padregraf.addChild(pastel);
                          padregraf.addChild(pstleg);
                         
                      }
                      else{
                          if(tipo==1){
                              //Crea el grafico
                              linea=new LineChart;
                              linea.id="graficoinicial";
                              linea.dataProvider=datagraf;
                              linea.showDataTips=true;
                              linea.width=384;
                              linea.height=157;
                              linea.x=0;
                              linea.y=0;
                             
                              //Crea las agrupaciones por categoria
                              vAxis = new CategoryAxis();
                              vAxis.categoryField = "campo" ;
                              vAxis.dataProvider =  datagraf;
                              linea.horizontalAxis = vAxis;

       

                              //Crea la serie
                              lnserie= new LineSeries;
                              lnserie.xField="campo";
                              lnserie.yField="valor";
                              lnserie.displayName="Series 1";
                              miserie.push(lnserie);
                             
                              //Agrega la serie al grafico
                              linea.series=miserie;
                             
                              //Agrega el grafico al modulo
                              padregraf.addChild(linea);
                          }
                          else{
                              //Crea el grafico
                              columna=new ColumnChart;
                              columna.id="graficoinicial";
                              columna.dataProvider=datagraf;
                              columna.showDataTips=true;
                              columna.width=384;
                              columna.height=157;
                              columna.x=0;
                              columna.y=0;
                             
                              //Crea las agrupaciones por categoria
                              vAxis = new CategoryAxis();
                              vAxis.categoryField = "campo" ;
                              vAxis.dataProvider =  datagraf;
                              columna.horizontalAxis = vAxis;
                             
                              //Crea la serie
                              clmserie= new ColumnSeries;
                              clmserie.xField="campo";
                              clmserie.yField="valor";
                              clmserie.displayName="Series 1";
                              miserie.push(clmserie);
                             
                              //Agrega la serie al grafico
                              columna.series=miserie;
                             
                              //Agrega el grafico al modulo
                              padregraf.addChild(columna);   
                          }
                      }
                  }

       

              ]]>
          </mx:Script>

       

      This is a simple pie chart that I create in other module

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="811" height="323" backgroundColor="#474747" creationComplete="rootgrafico();">
         
          <mx:Script>
              <![CDATA[
                  import mx.rpc.events.FaultEvent;
                  import mx.rpc.events.ResultEvent;       
                  import mx.controls.Alert;
                 
                  //Propiedades
                  [Bindable]public var tipoGraf:int=4;
                  [Bindable]private var varGrafPst:XMLList; 
                  [Bindable]public var enlace:int;
                 
                  //Metodos
                  public function rootgrafico():void{
                      parentApplication.casita.source="img/homen.png";
                      var valor:int=parentApplication.valorActualGrafico;
                      enlace=valor;
                     
                      switch(valor){
                          case 0:
                                  tipoGraf=4;
                                  break;
                          case 1:
                                  tipoGraf=1;
                                  break;
                          case 2:
                                  tipoGraf=2;
                                  break;
                          case 3:
                                  tipoGraf=3;
                                  break;
                          case 4:
                                  tipoGraf=5;
                                  break;
                      }
                     
                      var params:Object ={};
                      params["id_cliente"]=1;
                      params["tipo"]=tipoGraf;
                      grafBarraHT.send(params);
                  }
                 
                  public function resultGraf(event:ResultEvent):void{
                      varGrafPst=event.result.dato;
                      var piechart1:PieChart=this.piechart1;
                      piechart1.dataProvider=varGrafPst;
                  }
                 
                  public function errorPst():void{
                      Alert.show("Tiempo de espera agotado", 'Green Media Console', mx.controls.Alert.OK);
                  }
                 
                  public function cambiagraf(valor:int):void{
                      parentApplication.cargaGrafico(valor,enlace);
                  }
              ]]>
          </mx:Script>
         
          <mx:Canvas x="57" y="5" width="697" height="311" backgroundColor="#393939">
         
              <mx:PieChart x="10" y="25" id="piechart1" height="232" width="484" color="#FFFFFF" dataProvider="{varGrafPst}" showDataTips="true">
                  <mx:series>
                      <mx:PieSeries displayName="Series 1" field="valor" nameField="campo" labelPosition="callout"/>
                  </mx:series>
              </mx:PieChart>
             
              <mx:Legend dataProvider="{piechart1}" x="497" y="25" color="#FFFFFF" width="190" height="232"/>

       

          </mx:Canvas>
         
          <mx:HTTPService id="grafBarraHT" url="http://www.mypage.com/charts.php" result="resultGraf(event)" fault="errorPst()" method="POST" resultFormat="e4x">
          </mx:HTTPService>
         
      </mx:Module>