This example shows how to create a Pie chart that counts test cases (it can be anything else, of course). Source code is available here.
Pie chart is bound to an ArrayCollection (don’t forget to insert [Bindable] property – without it the Pie chart won’t work of course). The showDataTips="true" property displays nice percentage information in Flash when you hover your mouse over it. resultHandlerStatCorrectTCs and resultHandlerStatFailedTCs are async functions that gather data for the Pie chart.
<mx:PieChart x="50" y="90" id="piechart1" dataProvider="{tcPercResults}" showDataTips="true" width="300" height="300">
<mx:series>
<mx:PieSeries displayName="TestCases" field="Amount" nameField="Expense" explodeRadius=".12"/>
</mx:series>
</mx:PieChart>
<mx:Legend dataProvider="{piechart1}" x="0" y="90"/>
//Statistics
[Bindable]
public var tcPercResults:ArrayCollection = new ArrayCollection([
{Expense:"Failed", Amount:2000},
{Expense:"Success", Amount:1000},
]);
protected function statCanvas_creationCompleteHandler(event:FlexEvent):void
{
//get correct TCs
var resultObjCorrectTCs:AsyncToken;
var responderCorrectTCs:AsyncResponder = new AsyncResponder( resultHandlerStatCorrectTCs, faultHandlerForAsyncCall );
resultObjCorrectTCs = testService.getCorrectTCCount();
resultObjCorrectTCs.addResponder( responderCorrectTCs );
//get failed TCs
var resultObjFailedTCs:AsyncToken;
var responderFailedTCs:AsyncResponder = new AsyncResponder( resultHandlerStatFailedTCs, faultHandlerForAsyncCall );
resultObjFailedTCs = testService.getFailedTCCount();
resultObjFailedTCs.addResponder( responderFailedTCs );
}
public function resultHandlerStatCorrectTCs( event:ResultEvent, token:Object=null ):void
{
//Alert.show( "RESULT: "+ event.result as String );
//var rpcRes:int = event.result as int;
var rpcRes:int = int(event.result);
this.statCorrectTCs = rpcRes;
//set Correct TC on a graph
var resultCorr:Object = tcPercResults.getItemAt(1);
resultCorr["Amount"] = this.statCorrectTCs;
tcPercResults.setItemAt(resultCorr,1);
}
public function resultHandlerStatFailedTCs( event:ResultEvent, token:Object=null ):void
{
//Alert.show( "RESULT: "+ event.result as String );
//var rpcRes:int = event.result as int;
var rpcRes:int = int(event.result);
this.statFailedTCs = rpcRes;
//set Failed TC on a graph
var result:Object = tcPercResults.getItemAt(0);
result["Amount"] = this.statFailedTCs;
tcPercResults.setItemAt(result,0);
}
No comments:
Post a Comment
If you like this post, please leave a comment :)