Data Based Renderers
June 6th, 2006
[comments]: http://www.quietlyscheming.com/blog/2006/06/06/flex-charting-example-data-based-renderers/
[demo]: http://demo.quietlyscheming.com/dataBasedRenderers/index.html
[src]: http://demo.quietlyscheming.com/dataBasedRenderers/srcview/index.html
[zip]: http://demo.quietlyscheming.com/dataBasedRenderers/srcview/DataBasedRenderers.zip
There’ve been a couple of questions on the Flex lists lately about how to write custom renderers that draw a chart item differently based on the value it’s representing. I plan to flesh this out more over time, but to start off, here’s an example of a PieChart that renders its wedges with different colors based on whether the value they represent pass a particular threshold.
A couple of notes:
* Pie Series item renderers are the trickiest of the bunch. This should serve as a decent example of how to write one.
* custom renderers can choose what features of the parent series they want to support, based on where and how they’ll be used. In this case, I chose to support stylable strokes, but not support the ‘innerRadius’ feature of the PieChart.
* This item renderer was written to make the thresholds configurable, by defining a simple AS value class and assigning it to a property in the MXML. Remember that MXML is easy to extend with custom classes…that goes for non-visual classes too.
* If you like the idea but want it to work differently or for a different chart type, grab the code and make it work for you. I wrote it to be easy to move to other scenarios, and it’s pretty well commented.
And, while clearly I have a bit of an advantage, I threw this example together in the past 25 minutes or so. So take heart that once you get your hands dirty, extending charts can be fast and effortless ;)
### * [Threshold based Pie Chart][demo]
### * [view source][src]
### * [download source][zip]
Feedback or thoughts on this example, as well as requests for other examples you’d like to see, are much appreciated. [Leave comments, suggestions, criticisms here.][comments]
June 6th, 2006 at 9:31 am
[...] Check out the example here, then come back and leave feedback and comments. [...]