Chart Flex




    
        
        import mx.graphics.IFill;
        import mx.graphics.SolidColor;
        import mx.collections.ArrayCollection;
        import mx.charts.ChartItem;
        import mx.charts.series.items.ColumnSeriesItem;
        [Bindable]
        public var sales:ArrayCollection = new ArrayCollection([
            { Name:"Reiner", SalesGoal:65000, CurrentAmount:69000 },
            { Name:"Klaus", SalesGoal:40000, CurrentAmount:38000 },
            { Name:"Alan", SalesGoal:40000, CurrentAmount:44000 },
            { Name:"Wolfgang", SalesGoal:48000, CurrentAmount:33000 },
            { Name:"Francis", SalesGoal:22000, CurrentAmount:20000 },
            { Name:"Klaus-Jurgen", SalesGoal:50000, CurrentAmount:55000 },
            { Name:"Martin", SalesGoal:44000, CurrentAmount:70000 },
            { Name:"Mac", SalesGoal:40000, CurrentAmount:35000 },
            { Name:"Friedemann", SalesGoal:38000, CurrentAmount:38000 },
            { Name:"Bruno", SalesGoal:42000, CurrentAmount:40000 }
            ]);
        private function myFillFunction(element:ChartItem, index:Number):IFill
        {
            var item:ColumnSeriesItem = ColumnSeriesItem(element);
            trace("--------------------------------------------------");
            trace("Item index: " + index);
            trace("Sales Person: " + item.xValue);
            trace("Current Amount: " + currSalesSeries.items[index].yValue);
            trace("Sales Goal: " + item.yValue);
            // Set default color and alpha.
            var c:SolidColor = new SolidColor(0x00CC00);
            // Use the yNumber properties rather than the yValue properties
            // because the conversion to a Number is already done for
            // you. As a result, you do not have to cast them to a Number,
            // which would be less efficient.
            var goal:Number = item.yNumber;
            var currentAmount:Number = currSalesSeries.items[index].yNumber;
            // Determine if the goal was met or not.
            var diff:Number = currentAmount - goal;
            if (diff >= 0) {
              // Sales person met their goal.
              return c;
            } else if (diff < 0) {
             // Sales person did not meet their goal.
             c.color = 0xFF0000;
             c.alpha = .2;
            }
            return c;
        }
      
    

    
                    showDataTips="true">
            
                
            

            
                
            

            
                                    yField="CurrentAmount" displayName="Current Sales">
                    
                        
                    

                
                                    yField="SalesGoal" fillFunction="myFillFunction"
                    displayName="Sales Goal">