Exploding pie charts, part 2
In one of my first blogs I demoed a pie chart that made each of the wedges from the pie explode out the way when its item in the legend was rolled over by the mouse.
The pie chart also had a nice effect when it was shown in that it filled up in a circular manor.
You can check out the app here.
After a comment/question from the previous post asking about something I didn’t explain, I thought that it deservered its own post rather than just an edit of the original.
So the question was how do you get the circular effect, and how do you do ‘(… %)’ in the legend?
The effect
Firstly set up the effect
Then whatever ID you have given your pie series you’d do the following (I called my one ‘seriesOne’)
seriesOne.setStyle('showDataEffect', doughnut);
(I did this set up in the script block on creation complete or show + I nulled the effect/DP’s on hide so that you get the full effect each time)
If you wish to get the full opening of the circle effect then the data must be empty to start with as the effect just changes between the current and the new values.
The second part of the question was to do with the labels on the legend. This one is all to do with how you set up your dataprovider for the pie chart.
The label
I start of with loading in the data from an XML file (if you use some HTTP tool you should be able to see the data). It goes something like the following
blah
item 1
37.55
item 2
13.33
As you’ll see from the data there is no ‘%’. So what I do is when I load the data I construct an object VO (value object).
This VO contains the name, item and a label. The label is just the name + ‘(‘ + value +’%)’. Then the arrayCollection I use for the dataprovider is just a collection of these object VO’s.
Essentially my VO is this,
var obj : Object =new Object();
obj.name = 'item 1';
obj.value = 37.55;
obj.label = obj.name + '(' + obj.value +'%)';
The legend looks at the data for the pie chart and sees the label property and uses that as it is.
This may make you ask about the datatip for the actual pie chart as it doesn’t contain the brackets. Well for that I had to implement a dataTipFunction.
This function took the form,
private function returnToolTip(hitData:HitData):String {
return hitData.item.name + ' ' +hitData.item.value + '%';
}
and you just can set this in the MXML of the pie chart.
Well hopefully thats explained in a reasonable way, I’d love to open the entire source for this but without reworking it (commercial reasons) I can’t.
Check out part one of the blog here.
[ad name=”ad-1″]