Archive for category axiis
Axiis Drill Down Example
Posted by admin in actionscript, axiis, data visualization, flex, tutorial on November 2nd, 2009
I’ve seen a number of requests for a drill down version of an Axiis chart. We have a current client that will need that functionality as well so I figured I’d give it a shot.
The approach I’m taking is pretty straight forward. Put a drill down layout on the stage and make it invisible initially. When the user clicks on an item in the primary chart that we want to drill in, capture the event, set a dataProvider specific to the portion of the data that represents the drill down, hide the primary layout and show the drill down layout.
Building off the familiar approach for the Axiis examples, add a few objects for the drill down layout to use
<mx:Object id=“dataProvider”/> <mx:String id=“verticalField”/> <mx:String id=“dataField”>date</mx:String> <mx:String id=“labelField”>date.value</mx:String> <mx:Object id=“drilldataProvider”/> <mx:String id=“drilldataField”/> <mx:String id=“drilllabelField”/>
The drill down layout can be whatever type you choose. Here I’m just going to display the data as a simple bar chart.
<axiis:HBoxLayout
id=“drillDownLayout”
x=“25”
y=“0”
showDataTips=“true”
height=“{dc.height-70}”
width=“{dc.width-25}”
visible=“false”
dataProvider=“{drilldataProvider}”
percentGap=“0”
dataField=“{drilldataField}”
labelField=“{drilllabelField}”
itemClick=“this.itemClick(event);”>
<axiis:drawingGeometries>
<degrafa:RegularRectangle
id=“drillRectangle”
x=“{drillDownLayout.currentReference.x}”
y=“{drillDownLayout.height-vScale.valueToLayout(drillDownLayout.currentValue)}”
width=“{drillDownLayout.currentReference.width}”
height=“{vScale.valueToLayout(drillDownLayout.currentValue)}”
stroke=“{colStroke}”/>
<degrafa:RasterText
text=“{drillDownLayout.currentLabel}”
fontFamily=“Arial”
align=“center”
x=“{drillDownLayout.currentReference.x}”
width=“{drillDownLayout.currentReference.width}”
y=“{drillDownLayout.height+5}”/>
</axiis:drawingGeometries>
</axiis:HBoxLayout>
The only real piece of interest in this is the addition of a handler for the itemClick event.
itemClick="this.itemClick(event)"
Here’s the code that will handle the click of an item in the layout. Note that it will check to see which layout is currently visible so we can get back to the primary chart.
public function itemClick(evt:LayoutItemEvent):void
{
// Switch back to main view
if ( this.drillDownLayout.visible )
{
this.drilldataProvider = null;
this.drillDownLayout.visible = false;
this.hLayout.visible = true;
dc.invalidateDisplayList();
}else {
var ac:ArrayCollection = evt.item.layout.dataProvider as ArrayCollection;
this.hLayout.visible = false;
this.drillDownLayout.visible = true;
this.drilldataField = &quot;value&quot;;
this.drilllabelField = &quot;value&quot;;
this.drillRectangle.fill = ( evt.item.data.type == "receivables" ) ? this.receivablesStack.fill : this.payablesStack.fill;
this.drilldataProvider = ac;
dc.invalidateDisplayList();
}
}