Quadrant Chart creation in flex

Create mxml file

<![CDATA[

import mx.collections.ArrayCollection;

import mx.controls.Button;

import mx.rpc.events.FaultEvent;

import mx.rpc.events.ResultEvent;

import mx.controls.Label;

import qs.charts.dataShapes.*;

import mx.collections.ArrayCollection;

import mx.graphics.*;

import mx.charts.PlotChart;

import mx.charts.Legend;

import mx.charts.LinearAxis;

import mx.charts.HitData;

import mx.charts.series.PlotSeries;

import mx.core.IFlexDisplayObject;

import mx.collections.*;

import mx.controls.Alert;

import mx.utils.ObjectUtil;

[Bindable]

public var tmpQuery:String = " select * from quadrant order by id ";

[Bindable]

public var tmpQueryMax:String = "select max(abs(cm)) as cm,max(abs(sr)) as sr from quadrant ";

[Bindable]

public var arrDatabases:ArrayCollection = new ArrayCollection();

[Bindable]

public var arrDatabasesMax:ArrayCollection = new ArrayCollection();

[Bindable]

public var arrDatabases0:ArrayCollection = new ArrayCollection();

[Bindable]

public var arrDatabases1:ArrayCollection = new ArrayCollection();

[Bindable]

public var arrDatabases2:ArrayCollection = new ArrayCollection();

[Bindable]

public var arr:Array = new Array();

[Bindable]

private var firstAxis:Array = new Array();

[Bindable]

private var firstTmp:int=0;

[Bindable]

private var firstAxisMax:Number=0;

[Bindable]

private var firstTmp1:int=0;

[Bindable]

private var firstAxisMin:Number=0;

[Bindable]

private var firstAxisNeg:Number=0;

[Bindable]

private var firstAxisRes:Number=0;

[Bindable]

[Embed('/css/icons/MTNULogo.png')]

private var backIcon:Class;

private var fileRef:FileReference;

[Bindable]

public var expenses:ArrayCollection = new ArrayCollection([

{Month:"May", contr:1,subs:3},

{Month:"Jun", contr:2,subs:1},

{Month:"July", contr:5,subs:2}

]);

private function init():void

{

quadrant_id.getQuadrant(tmpQuery);

quadrant_id_max.getQuadrantMax(tmpQueryMax);

}

/*public function drawData():void

{

canvas.clear();

canvas.lineStyle(0,0,0);

canvas.beginFill(0x66FF33);

canvas.drawRect(50,Edge.TOP,Edge.RIGHT,50);

canvas.endFill();

canvas.beginFill(0xFFFF66);

canvas.drawRect(Edge.LEFT,Edge.TOP,50,50);

canvas.endFill();

canvas.beginFill(0xFFFFFF);

canvas.drawRect(50,50,Edge.RIGHT,Edge.BOTTOM);

canvas.endFill();

canvas.beginFill(0xFF9999);

canvas.drawRect(Edge.LEFT,50,50,Edge.BOTTOM);

canvas.endFill();

canvas.beginFill(0x66FF33);//Top Right

canvas.drawRect(0,Edge.TOP,Edge.RIGHT,0);

canvas.endFill();

canvas.beginFill(0xFFFF66);//Top Left

canvas.drawRect(Edge.LEFT,Edge.TOP,0,0);

canvas.endFill();

canvas.beginFill(0xFFFFFF);//Bottom Right

canvas.drawRect(-0.5,0,Edge.RIGHT,Edge.BOTTOM);

canvas.endFill();

canvas.beginFill(0xFF9999);//Bottom left

canvas.drawRect(Edge.LEFT,0,0,Edge.BOTTOM);

canvas.endFill();

}*/

/**

This is for Visual Component Result handler

@param – Event

*/

private function QuadrantResultHandler(event:ResultEvent):void

{

arrDatabases = event.result as ArrayCollection;

arrDatabases0 = new ArrayCollection([arrDatabases.getItemAt(0)]);

arrDatabases1 = new ArrayCollection([arrDatabases.getItemAt(1)]);

arrDatabases2 = new ArrayCollection([arrDatabases.getItemAt(2)]);

//ObjectUtil.toString(arrDatabases[2]['Month'].toString()

//Alert.show(" "+arrDatabases1.toString());

//ObjectUtil.toString(arrDatabases[i-1]['month']).toString()

//var obj:Object = ObjectUtil.getClassInfo(arrDatabases0[0]);

//arr = obj.properties.toString().split(",");

//Alert.show("YY"+arr);

firstAxis = ["month_name","cm","sr"];

var str:String="";

for(var k:int =0;k<arrDatabases.length;k++)

{

//str += ObjectUtil.toString(arrDatabases[k]['month']).toString().replace("\""," ") +",";

var sts:String = ObjectUtil.toString(arrDatabases[k]['month']).toString();

sts = str_replace("\""," ",sts);

arr.push(sts);

//Alert.show(ObjectUtil.toString(arrDatabases[k]['month']).toString())

}

tmp0.displayName= arr[0];

tmp1.displayName= arr[1];

tmp2.displayName= arr[2];

}

private function str_replace( replace_with:String, replace:String, original:String ):String

{

var array:Array = original.split(replace_with);

return array.join(replace);

}

/**

Fault handler

@param – Event (event)

*/

private function faultHandler(event:FaultEvent):void

{

Alert.show(event.fault.message, "Could not load data feed");

}

private function saveChart(comp:DisplayObject):void

{

downloadChart(comp);

}

private function downloadChart(comp:DisplayObject):void

{

fileRef = new FileReference();

var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(comp);

fileRef.save(imageSnap.data, ".png");

}

public function defineVerticalLabel(cat:Object, pcat:Object,ax:LinearAxis):String

{

return (cat)+"%";

}

private function genericDataTipFormatter(hd:HitData):String

{

var series:PlotSeries = PlotSeries(hd.element);

var dataTip:String = "";

dataTip = "” + series.displayName + “\nCM Growth:” +hd.item[“cm”] + “%\nRevenue:” + hd.item[“sr”] + “%”;

return dataTip;

}

private function QuadrantMaxResultHandler(event:ResultEvent):void

{

arrDatabasesMax = event.result as ArrayCollection;

var cm:Number = arrDatabasesMax[0][‘cm’];

var sr:Number = arrDatabasesMax[0][‘sr’];

if(cm

.TitleStyle

{

fontSize:12;

}

<!–

–>

About ashokabhat

I am a C,C ,JAVA,Adobe Flex,.NET Programmer Currently working as a Software Developer
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s