Chart Flex


    
    xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark"
    creationComplete="initApp();" height="600">
  
    
                    elementOffset="0" minimumElementDuration="200" />
    

     
         
        import mx.collections.ArrayCollection; 
        import mx.charts.chartClasses.ChartBase; 
        import mx.charts.ChartItem; 
        import mx.charts.series.items.ColumnSeriesItem; 
        import mx.charts.PieChart; 
        import mx.charts.series.PieSeries; 
        import mx.charts.events.ChartItemEvent; 
        import mx.charts.Legend; 
    [Bindable]
    public var expenses:ArrayCollection = new ArrayCollection([
      {Month:"Jan", Profit:20, Expenses:15, Amount:145},
      {Month:"Feb", Profit:1, Expenses:2, Amount:60},
      {Month:"Mar", Profit:15, Expenses:5, Amount:3}
      ]);
        [Bindable] 
        public var expensesAC:ArrayCollection; 
        [Bindable] 
        public var newDataProviderAC:ArrayCollection; 
        private function resultHandler():void { 
            expensesAC = expenses; 
        } 
        private function initApp():void { 
            myColumnChart.addEventListener(ChartItemEvent.CHANGE, createNewChart); 
            setupPieChart(); 
        } 
        private function getNewDataProvider():ArrayCollection { 
            newDataProviderAC = new ArrayCollection(); 
            for (var i:int=0; i                var o:Object = new Object(); 
                o.Month = expensesAC.getItemAt(series1.selectedIndices[i]).month; 
                o.Expenses = expensesAC.getItemAt(series1.selectedIndices[i]).expenses; 
                newDataProviderAC.addItem(o); 
            } 
            return newDataProviderAC; 
        } 
        private var newChart:PieChart; 
        private var newSeries:PieSeries; 
        [Bindable] 
        private var explodedPiece:Array; 
        private function explodePiece(e:Event):void { 
            explodedPiece = new Array(); 
            explodedPiece[newSeries.selectedIndex] = .2; 
            newSeries.perWedgeExplodeRadius = explodedPiece; 
        } 
        private function setupPieChart():void { 
            newChart = new PieChart(); 
            newChart.showDataTips = true; 
            newChart.selectionMode = "single"; 
            newSeries = new PieSeries(); 
            newSeries.field = "Expenses"; 
            newSeries.nameField = "Month"; 
            newSeries.setStyle("labelPosition", "callout"); 
            newSeries.setStyle("showDataEffect", "interpol"); 
            var newSeriesArray:Array = new Array(); 
            newSeriesArray.push(newSeries); 
            newChart.series = newSeriesArray; 
            newChart.addEventListener(ChartItemEvent.CHANGE, explodePiece); 
            // Create a legend for the new chart. 
            var newLegend:Legend = new Legend(); 
            newLegend.dataProvider = newChart; 
            p1.addElement(newChart); 
            p1.addElement(newLegend); 
        } 
        private function createNewChart(e:Event):void { 
            newChart.dataProvider = getNewDataProvider(); 
        } 
      
    

    
        
    

    
        
            
        

                    showDataTips="true" dataProvider="{expenses}"
            selectionMode="multiple">
            
                                    displayName="Expenses" selectable="true" />