In a Flex 4.7 web application I'm trying to draw a simple pie chart in red and green colors.
So I have drawn a _red
circle and then right above it I have drawn a _green
circle:
And I was hoping to set an angle on the latter - to reduce it to a "slice of pie", but can't find any method or property for that in spark.primitives.Ellipse
Does anybody please have a good suggestion here?
My complete and simple test code is below:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
applicationComplete="init()">
<fx:Script>
<![CDATA[
private function init():void {
// XXX how to set _green angle?
}
]]>
</fx:Script>
<s:Ellipse id="_red" height="60" width="60" x="110" y="90">
<s:fill>
<s:SolidColor color="#CC0000" />
</s:fill>
</s:Ellipse>
<s:Ellipse id="_green" height="60" width="60" x="110" y="90">
<s:fill>
<s:SolidColor color="#66CC66" />
</s:fill>
</s:Ellipse>
</s:Application>
Because it is too heavyweight, I don't want to use mx.charts.PieChart, since the chart will be shown in an item renderer: Calculate a quotient in one table and store it in another table
Also, I've searched the net and all code examples drawing wedges call curveTo
multiple times, but I wonder if a simple mask to partially cover the _green
circle could be used instead?
One approach would be to draw wedges to a
<s:SpriteVisualElement>
or use fill as a mask usingnl.funkymonkey.drawing.DrawingShapes
:Ultimately ending up as:
Example MXML implementation:
Even leaner is to simply perform all drawing via low-level graphics operations instead of using the Spark ellipse primitive.