Get the data from selected row and show it in the graphics

Hi,
i am trying to show a graph when the user selects a row in the data grid but the chart is not showing up.  i am able to pull the data from the backend using php/mysql and populating the data grid successfully but i would like to show a chart based on what the user selects in the data grid.  pls. help.
Note, i am using flash builder 4
<?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" minWidth="955" minHeight="600" xmlns:summarybyallservice="services.summarybyallservice.*"
			   creationComplete="initApp()">
	
	<fx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.collections.ArrayCollection;
			import mx.events.FlexEvent;
			import mx.rpc.events.ResultEvent;
			import mx.utils.ArrayUtil;
			import mx.events.ListEvent;
			
			
			
			[Bindable] 
			private var mydata:ArrayCollection = new ArrayCollection();
			
			[Bindable]
			private var ac:ArrayCollection;
			
			/* Array for moving up and down */
			private var pos:Array = [1,2,3];
			
			/* Radius for the pie chart */       
			[Bindable]
			private var explRadius:Array = new Array();
			
			
			private function initApp():void
			{	
				summarybyallService.getAllSummary_by_all();
			}
			
			
			protected function summarybyallService_resultHandler(event:ResultEvent):void
			
			   {
				
				mydata = event.result as ArrayCollection;
			   }
			
			
			private function selectRow(e:ListEvent):void
			{    
				var j:int;
				
				try{	
					for(j;j< explRadius.length; j++)
					{
						explRadius[j]=0;
					}				
					explRadius[e.columnIndex -1]=.2;
					
					ac = new ArrayCollection([
						{Years:"Act FY10", Spend:e.itemRenderer.data.Actual_FY10, Values:e.itemRenderer.data.Actual_FY10 /2 },
						{Years:"Act FY11", Spend:e.itemRenderer.data.Actual_FY11 , Values:e.itemRenderer.data.Actual_FY11 /2},
						{Years:"Ann FY11", Spend:e.itemRenderer.data.Anualized_FY11, Values:e.itemRenderer.data.Anualized_FY11 /2 }
						
						
					]);
					
					
					theColumnChart.dataProvider =ac;
						
					
					/*thePieSeries.perWedgeExplodeRadius = explRadius; */
				}
				catch(er:*)
				{
					Alert.show(er.toString(),"Error");
				}
			}

			
		]]>
	</fx:Script>
	<fx:Declarations>
		
		<s:CallResponder id="getAllSummary_by_allResult"/>
		<summarybyallservice:SummarybyallService id="summarybyallService" 
												 fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" 
												 showBusyCursor="true"
												 result="summarybyallService_resultHandler(event)"/>
		
		<!-- Place non-visual elements (e.g., services, value objects) here -->
		<!-- Define chart effects -->
		
		<!--Column chart effect-->
		<mx:SeriesSlide id="slideIn" duration="1000" direction="up"/>
		<mx:SeriesSlide id="slideOut" duration="1000" direction="down" />
		<mx:SolidColor id="sc0" color="red" alpha=".3"/>
		<mx:Stroke id="stroke0" color="red" weight="1" alpha=".8"/>
	
	</fx:Declarations>
	
	<mx:DataGrid x="76" y="68" id="dGrid" dataProvider="{mydata}" width="427"
				 itemClick="selectRow(event)"
				 selectedIndex="0">
		<mx:columns>
			<mx:DataGridColumn headerText="Category" dataField="category"/>
			<mx:DataGridColumn headerText="Actual FY10" dataField="Actual_FY10"/>
			<mx:DataGridColumn headerText="Actual FY11" dataField="Actual_FY11"/>
			<mx:DataGridColumn headerText="Annualized FY11" dataField="Anualized_FY11"/>
		</mx:columns>
	</mx:DataGrid>
	
	
	
	
	<!--ColumnChart-->
	<mx:ColumnChart id="theColumnChart" 
					height="121" width="411"
					showDataTips="true" 
					selectionMode="single"
					type="clustered" y="238" x="76">
		<mx:horizontalAxis>
			<mx:CategoryAxis 
				dataProvider="{ac}" 
				categoryField="Years"/>
		</mx:horizontalAxis>
		
		<mx:verticalAxis>
			<mx:LinearAxis minimum="0" maximum="1500"/>
		</mx:verticalAxis>
		
		<mx:series>
			<mx:ColumnSeries 
				id="theColSeries"
				yField="Spend"
				xField="Years"
				stroke="{stroke0}"
				
				showDataEffect="slideIn"
				hideDataEffect="slideOut"/>
		</mx:series>
	</mx:ColumnChart>

</s:Application>

Open in new window

karinos57Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

petiexCommented:
It seems to work for me. You do have to CLICK a datagrid column to populate the graph. Maybe you want to change
itemClick="selectRow(event)"
to
change="selectRow(event)" ?

Because I don't have the summarybyallService code, to test this, I replaced the summarybyall service invocation with an assignment of a hard coded array collection to the one bound to the datagrid dataprovider:

initApp():void{
mydata =new ArrayCollection([
                {category:"Cheese",Actual_FY10:0,Actual_FY11:0,Anualized_FY11:4},
                {category:"Corn",Actual_FY10:522,Actual_FY11:123,Anualized_FY11:611},
                {category:"Okra",Actual_FY10:88,Actual_FY11:99,Anualized_FY11:90},
                {category:"Haggis",Actual_FY10:111,Actual_FY11:77,Anualized_FY11:100}]);
}
karinos57Author Commented:
thanks for your quick response.  i have tried your suggestion but still not working.  i can see the graph but without the bars or the spend; see attached.  thanks
Doc1.doc
petiexCommented:
The problem is that your data is larger than the limit for the graph.

You have
                <mx:verticalAxis>
                        <mx:LinearAxis minimum="0" maximum="1500"/>
                </mx:verticalAxis>
The smallest value in the screenshot you attached is like 200 million, so it is just to big to register on an axis whose maximum is 1500. Try changing the maximum to 1000000000.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

karinos57Author Commented:
it is working like a charm, thank you very much.  one last question:
how can i format the numbers with dolar signs and with no decimial.  I would like to see currency with no decimal.  thanks again for your time
petiexCommented:
Put this in your script area:

protected function myLabelFunction(item:Object, dgc:DataGridColumn):String{
     var str:String = item[dgc.dataField];
     return "$" + (str.indexOf(".") > -1) ? str.substring(0,str.indexOf(".")) : str;
}

Then, for each datagridcolumn that you want to format like that, add:
labelFunction="myLabelFunction"
petiexCommented:
Oops! Left out a crucial set of parentheses:

protected function myLabelFunction(item:Object, dgc:DataGridColumn):String{
     var str:String = item[dgc.dataField];
     return "$" + ((str.indexOf(".") > -1) ? str.substring(0,str.indexOf(".")) : str);
} 

Open in new window

karinos57Author Commented:
it is working fine but the numbers are not rounded up.  is there a way to round up the numbers - i don't know if i have to use currency formatter class.  thanks again for your help.
petiexCommented:
protected function myLabelFunction(item:Object, dgc:DataGridColumn):String {
       var str:int = Math.round(item[dgc.dataField]);
       return "$" + str;
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
karinos57Author Commented:
thank you very much.  it is working like a charm.  the only thing i would like to ask is to put comma in the proper place within the numbers but i already asked too much.  thanks again.
petiexCommented:
No, I think I can spare a numberformatter example:
        . . .
  private var nf:NumberFormatter;

  private function initApp():void {
            nf = new NumberFormatter();
            nf.useThousandsSeparator = true;
            nf.precision = 0;
            summarybyallService.getAllSummary_by_all();
  }
  protected function myLabelFunction(item:Object, dgc:DataGridColumn):String {
            return "$" + nf.format(Math.round(item[dgc.dataField]));
  }

Open in new window

karinos57Author Commented:
i am getting 2 errors:
the first one at this line: private var nf:NumberFormatter;
and the error is
1046: Type was not found or was not a compile-time constant: NumberFormatter.      

2nd at this line:nf = new NumberFormatter();
and the error is :
"Call to a possibly undefined method NumberFormatter."
petiexCommented:
add
import mx.formatters.NumberFormatter;
up there with the other import statements.
karinos57Author Commented:
you are the man.  thnx again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Flex

From novice to tech pro — start learning today.