Hi Chris. It sounds like what you're trying to do, in SQL metaphors, is
essentially select a COUNT() with a GROUP BY region, and put the result
into a pie chart. This kind of data manipulation is not part of the
charts...we assume you're using some other solution higher in the chain
(i.e., either doing it explicitly in the query, or building it by hand
from actionscript), and focus purely on the rendering of the data. So
yes, assuming you've got your data local and it's not an obscene amount
of data, it should require only a minor bit of actionsctript to
sythesize a grouped, counted dataset from the one you have:
var groupedDataMap:Object = {};
var offices:XMLList = myData.office;
for(var i:int = 0;i<offices.length();i++)
{
var region:String = offices[i].region.toString()
if ( region in groupedDataMap )
groupedDataMap[region]++;
else
groupedDataMap[region] = 1;
}
var groupedDataSet:Array =[]
for (var aRegion:String in groupedDataMap)
{
groupedDataSet[i] = { region: aRegion, count:
groupedDataMap[aRegion] };
}
Ely.
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Chris MacGregor
Sent: Thursday, January 18, 2007 10:03 AM
To: [email protected]
Subject: [flexcoders] XML and pie charts
Hello,
I'm building a data visualizer for a company based on it's sales
fleet. I've got a few questions about XML and pie charts and I'm
hoping someone can point me in the right direction to figure this one
out.
So, I've got this XML document that I'm importing into FLEX that looks
a bit like this (simplified):
<salesforce>
<office>
<name>Office A</name>
<region>Texas</region>
<revenue>100000</revenue>
</office>
<office>
<name>Office B</name>
<region>Texas</region>
<revenue>150000</revenue>
</office>
<office>
<name>Office C</name>
<region>Iowa</region>
<revenue>80000</revenue>
</office>
<office>
<name>Office D</name>
<region>Maine</region>
<revenue>110000</revenue>
</office>
</salesforce>
I've got some datagrids set up to explore the XML just fine, but I'd
also like to make pie charts that provide visuals for the client. For
example, I'd like a pie chart that shows where the offices are located
by region (so 50% texas, 25% Iowa and 25% Maine) and a second pie
chart that displays revenue by state (57% Texas, 18% Iowa and 25%
Maine).
I'm finding that there isn't a simple way to collect this information
using something like
dataProvider="{service.lastResult.salesforce.office[region]}" for the
pie chart. I think I am going to have to step through the XML and
build this information dynamically, or am I wrong? Can FLEX handle this?
How would you go about setting these types of pie charts up to display
from the XML referenced above?
CHris