1 Reply Latest reply on Aug 9, 2010 7:01 AM by rootsounds

    Type Coercion failed: cannot convert mx.charts::ColumnChart@6b380a1 to mx.charts.chartClasses.Series

    raydedon

      cant we set style of labelPosition of a columnSeries which has a dataFuntion.....

      whenever i try to setstyle for a columnseries which has datafunction defined throws an error of type :

      Type Coercion failed: cannot convert mx.charts::ColumnChart@6b380a1 to mx.charts.chartClasses.Series.

       

       

       

      <?xml version="1.0"?>

       

      <!-- charts/UsingBarSets.mxml -->

       

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">

       

        <mx:Script><![CDATA[

       

            import mx.controls.Alert;

       

          import mx.controls.Button;

       

          import mx.charts.series.ColumnSeries;

       

          import mx.charts.series.ColumnSet;

       

          import mx.charts.LinearAxis;

       

          import mx.charts.CategoryAxis;

       

          import mx.charts.ColumnChart;

       

          import mx.charts.chartClasses.AxisBase;

       

          import mx.charts.chartClasses.Series;

       

          import mx.charts.chartClasses.IAxis;

       

          import mx.charts.series.LineSeries;

       

          import mx.charts.AxisRenderer;

       

           import mx.charts.Legend;

       

           import mx.charts.BarChart;

       

           import mx.charts.series.BarSet;

       

           import mx.charts.series.BarSeries;

       

           import mx.collections.ArrayCollection;

       

           public var c:ColumnChart = new ColumnChart();

       

           [Bindable]

       

           private var yearlyData:ArrayCollection = new ArrayCollection([

       

              {month:"January", revenue:120, costs:45,

       

                  overhead:102, oneTime:23},

       

              {month:"February", revenue:108, costs:42,

       

                  overhead:87, oneTime:47},

       

              {month:"March", revenue:150, costs:82,

       

                  overhead:32, oneTime:21},

       

             ]);

       

           private function initApp():void {

       

              c.dataProvider = yearlyData;

       

              c.showDataTips = true;

       

              var hAxis:CategoryAxis = new CategoryAxis();

       

              hAxis.categoryField = "month";  

       

              /* hAxis.dataFunction = myAxisDataFunction; */

       

              /* hAxis.labelFunction = myCategoryLabelFunction; */

       

              var hRender:AxisRenderer = new AxisRenderer();

       

              hRender.axis = hAxis as IAxis;

       

              hRender.visible = true;

       

              hRender.placement = "bottom";

       

              var xRenderArray:Array = new Array();

       

              xRenderArray.push(hRender);

       

              var vAxis:LinearAxis = new LinearAxis();


              var vRender:AxisRenderer = new AxisRenderer();
              vRender.axis = vAxis;
              vRender.placement = "left";
              /* c.verticalAxis = vAxis; */

       

              var mySeries:Array = new Array();

       

              var outerSet:ColumnSet = new ColumnSet();
              outerSet.type = "clustered";
              var series1:ColumnSeries = new ColumnSeries();
              series1.dataFunction = mySeriesDataFunction;
              series1.setStyle("labelPosition", "outside");

              /* series1.yField = "revenue"; */
              series1.displayName = "Revenue";
              series1.horizontalAxis = hAxis;
              series1.verticalAxis = vAxis;
              outerSet.series = [series1];

       

              var innerSet:ColumnSet = new ColumnSet();
              innerSet.type = "stacked";
              var series2:ColumnSeries = new ColumnSeries();
              var series3:ColumnSeries = new ColumnSeries();
              series2.yField = "costs";
              series2.setStyle("labelPosition", "inside");
              Alert.show("style is: " + series2.getStyle("labelPosition"));
              trace("style: ", series2.getStyle("labelPosition"));
              series2.displayName = "Recurring Costs";
              series2.horizontalAxis = hAxis;
              series2.verticalAxis = vAxis;       
              series3.yField = "oneTime";
              series3.displayName = "One-Time Costs";
              series3.horizontalAxis = hAxis;
              series3.verticalAxis = vAxis;
              mySeries.push(series2);
              mySeries.push(series3);      
              innerSet.series = mySeries;

       

              var ls:LineSeries = new LineSeries();
              ls.yField = "costs";
              ls.displayName = "Cost2";
              ls.horizontalAxis = hAxis;
              ls.verticalAxis = vAxis;       

       

              c.series = [outerSet, innerSet, ls];
              c.horizontalAxisRenderers = xRenderArray;
              /* c.horizontalAxisRenderer = hRender; */
              c.verticalAxisRenderers = [vRender];

       


              var l:Legend = new Legend();
              l.dataProvider = c;

       

              var b:Button = new Button();
              b.label = "popseries";
              b.addEventListener(MouseEvent.CLICK,
                  function ():void{
                      var series:Array = c.series;
                      series.pop();
                      c.series = null;
                      c.series = series;     
                  }
              );

       

              panel2.addChild(c);
              panel2.addChild(l);
              panel2.addChild(b);
           }

       

          private function mySeriesDataFunction(series:Series, item:Object, fieldName:String):Object{
              var obj:Object;

       

              if(fieldName == "yValue"){
                  obj = item["revenue"];
              }else if(fieldName == "xValue"){
                  obj = item["month"];
              }else{
                  obj = null;
              }

       

              return obj;
          }

       

        ]]></mx:Script>

       

        <mx:Panel title="Mixed Sets Chart Created in ActionScript" id="panel2">
        </mx:Panel>
      </mx:Application>