I am a novice FLEX Developer I want to separate the data from the PHP call to Different CollectionArrays So that I can use the data for a bar-graph;
I created a static version of the bar-graph and separated the Collection array manually I don't want this done manually I need to do it dynamically. So what I am trying to understand is where to put the event-listener how to add to a collectionArray then once the collection array(s) are built. use that information to build the bar graphs...
/*
*
36, > 2 years, Compliance
6, 0-90 Days, Compliance
32, 181-365 Days, Compliance
72, 366-730 Days, Compliance
15, 91-180 Days, Compliance
4, > 2 years, Medium/Low
118, 0-90 Days, Medium/Low
143, 181-365 Days, Medium/Low
29, 366-730 Days, Medium/Low
67, 91-180 Days, Medium/Low
10, > 2 years, Patient Safety
2, 0-90 Days, Patient Safety
17, 181-365 Days, Patient Safety
18, 366-730 Days, Patient Safety
5, 91-180 Days, Patient Safety
*/
I need the above information translated to the bottom information using a onload finished event listener.
[Bindable]
public var _compliance:ArrayCollection = new ArrayCollection([
{Count:36, Time : "> 2 years" },
{Count:6, Time : "0-90 Days" },
{Count:32, Time : "181-365 Days" },
{Count:72, Time : "366-730 Days" },
{Count:15, Time : "91-180 Days" }
]);
[Bindable]
public var _medlow:ArrayCollection = new ArrayCollection([
{Count:4, Time : "> 2 years" },
{Count:118, Time : "0-90 Days" },
{Count:143, Time : "181-365 Days" },
{Count:29, Time : "366-730 Days" },
{Count:67, Time : "91-180 Days" }
]);;
[Bindable]
public var _patient:ArrayCollection = new ArrayCollection([
{Count:10, Time : "> 2 years" },
{Count:2, Time : "0-90 Days" },
{Count:17, Time : "181-365 Days" },
{Count:18, Time :开发者_JAVA百科 "366-730 Days" },
{Count:5, Time : "91-180 Days" }
]);;
Like @J_A_X said, data like this makes things a bit more difficult because it becomes your job to parse it. But, no biggie. You can just do some split
work to do the parsing here. Assuming your lines are delimited with "\n", then the following should work. I am using ActionLinq which makes data processing a breeze.
I am assuming your data from the server has been put in a string called serverData
:
private function parseLine(line:String):Object {
var split:Array = line.split(", ");
return { Count: Number(split[0]), Time: split[1], Category: split[2] };
}
private function getDataBy(category:String):ArrayCollection {
return Enumerable.from(serverData.split("\n"))
.select(parseLine)
.where(function(x:*):Boolean { return x.Category == category })
.toArrayCollection();
}
[Bindable] public var _compliance:ArrayCollection;
[Bindable] public var _medlow:ArrayCollection;
[Bindable] public var _patient:ArrayCollection;
Then, when you get your data back from the server, you can populate your ArrayCollection
s:
_compliance = getDataBy("Compliance");
_medlow = getDataBy("Medium/Low");
_patient = getDataBy("Patient Safety");
Thanks Brian I like yours way better then my solution as its smaller and reusable getAllItemsResult is the data set from the call to the server.
public function setData():void{
var t_com:Object = new Object();
var t_med:Object = new Object();
var t_pat:Object = new Object();
for (var i:Object in getAllItemsResult.lastResult)
{
var n:Object = getAllItemsResult.lastResult[i];
var t:Object = new Object();
switch(n['Priority']){
case 'Compliance':
t = {
'Count' : getAllItemsResult.lastResult[i]['THECOUNT'],
'Time': getAllItemsResult.lastResult[i]['CAPA_AGE']
}
t_com.addItem(t);
break;
case 'Medium/Low':
t = {
'Count' : getAllItemsResult.lastResult[i]['THECOUNT'],
'Time': getAllItemsResult.lastResult[i]['CAPA_AGE']
}
t_med.addItem(t);
break;
case 'Patient Safety':
t = {
'Count' : getAllItemsResult.lastResult[i]['THECOUNT'],
'Time': getAllItemsResult.lastResult[i]['CAPA_AGE']
}
t_pat.addItem(t);
break;
default:
break;
}
}
var sortArr:Array = new Array("0-90 Days","91-180 Days","181-365 Days","366-730 Days","> 2 years");
//loop through array then add items to occording to array length
}
]]>
now I got to figure out how to sort the darn thing!
精彩评论