Featured Post

Xml Accordion Banner v3.0

xml driven. as3,size just 6kb. accordion style. support auto play. support load jpg,gif,pnd,swf files. support descriptions(html format) of each loaded object. support add link to open new window. support set all style(delay time,color,alpha…) throught edit xml. $8 BUY NOW IN ACTIVEDEN.NET

Read More

FLEX OLAP(OLAPDataGrid)

Posted by activetofocus | Posted in Flash Technology | Posted on 24-10-2009

Tags: ,

0

The OLAPDataGrid control expands on the functionality of the
AdvancedDataGrid control to add support for the display of the
results of OLAP queries. Like all Flex data grid controls, the
OLAPDataGrid control is designed to display data in a two-dimensional
representation of rows and columns.
source:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
verticalAlign="top"    horizontalAlign="center"
backgroundGradientColors="[0x000000,0x323232]" paddingTop="0"
creationComplete="creationCompleteHandler();"
viewSourceURL="srcview/index.html">     
<mx:Script>
<![CDATA[
import mx.rpc.AsyncResponder;
import mx.rpc.AsyncToken;
import mx.olap.OLAPQuery;
import mx.olap.OLAPSet;
import mx.olap.IOLAPQuery;
import mx.olap.IOLAPQueryAxis;
import mx.olap.IOLAPCube;
import mx.olap.OLAPResult;
import mx.events.CubeEvent;
import mx.controls.Alert;
import mx.collections.ArrayCollection;   
// Format of Objects in the ArrayCollection:
//
//  data:Object = {
//    customer:"AAA", 
//    product:"ColdFusion",
//    quarter:"Q1"
//    revenue: "100.00" 
//  }
// 
[Bindable]
private var flatData:ArrayCollection = new ArrayCollection(
[
{customer:"AAA", product:"ColdFusion", quarter:"Q1", revenue:210, cost:25},
{customer:"AAA", product:"Flex", quarter:"Q2", revenue:210, cost:25},
{customer:"AAA", product:"Dreamweaver", quarter:"Q3", revenue:250, cost:125},
{customer:"AAA", product:"Flash", quarter:"Q4", revenue:430, cost:75},
{customer:"BBB", product:"ColdFusion", quarter:"Q2", revenue:125, cost:20},
{customer:"BBB", product:"Flex", quarter:"Q3", revenue:210, cost:20},
{customer:"BBB", product:"Dreamweaver", quarter:"Q4", revenue:320, cost:120},
{customer:"BBB", product:"Flash", quarter:"Q1", revenue:280, cost:70},
{customer:"CCC", product:"ColdFusion", quarter:"Q3", revenue:375, cost:120},
{customer:"CCC", product:"Flex", quarter:"Q4", revenue:430, cost:120},
{customer:"CCC", product:"Dreamweaver", quarter:"Q1", revenue:470, cost:220},
{customer:"CCC", product:"Flash", quarter:"Q2", revenue:570, cost:170},
{customer:"AAA", product:"ColdFusion", quarter:"Q4", revenue:215, cost:90},
{customer:"AAA", product:"Flex", quarter:"Q1", revenue:210, cost:90},
{customer:"AAA", product:"Dreamweaver", quarter:"Q2", revenue:175, cost:190},
{customer:"AAA", product:"Flash", quarter:"Q3", revenue:670, cost:75},
{customer:"BBB", product:"ColdFusion", quarter:"Q1", revenue:175, cost:20},
{customer:"BBB", product:"Flex", quarter:"Q2", revenue:210, cost:20},
{customer:"BBB", product:"Dreamweaver",quarter:"Q3", revenue:120, cost:120},
{customer:"BBB", product:"Flash", quarter:"Q4", revenue:310, cost:70},
{customer:"CCC", product:"ColdFusion", quarter:"Q1", revenue:385, cost:120},
{customer:"CCC", product:"Flex", quarter:"Q2", revenue:340, cost:120},
{customer:"CCC", product:"Dreamweaver", quarter:"Q3", revenue:470, cost:220},
{customer:"CCC", product:"Flash", quarter:"Q4", revenue:270, cost:170},
{customer:"AAA", product:"ColdFusion", quarter:"Q1", revenue:100, cost:25},
{customer:"AAA", product:"Flex", quarter:"Q2", revenue:150, cost:25},
{customer:"AAA", product:"Dreamweaver", quarter:"Q3", revenue:200, cost:125},
{customer:"AAA", product:"Flash", quarter:"Q4", revenue:300, cost:75},
{customer:"BBB", product:"ColdFusion", quarter:"Q2", revenue:175, cost:20},
{customer:"BBB", product:"Flex", quarter:"Q3", revenue:100, cost:20},
{customer:"BBB", product:"Dreamweaver", quarter:"Q4", revenue:270, cost:120},
{customer:"BBB", product:"Flash", quarter:"Q1", revenue:370, cost:70},
{customer:"CCC", product:"ColdFusion", quarter:"Q3", revenue:410, cost:120},
{customer:"CCC", product:"Flex", quarter:"Q4", revenue:300, cost:320},
{customer:"CCC", product:"Dreamweaver", quarter:"Q1", revenue:510, cost:220},
{customer:"CCC", product:"Flash", quarter:"Q2", revenue:620, cost:170},
{customer:"AAA", product:"ColdFusion", quarter:"Q4", revenue:215, cost:90},
{customer:"AAA", product:"Flex", quarter:"Q1", revenue:210, cost:90},
{customer:"AAA", product:"Dreamweaver", quarter:"Q2", revenue:175, cost:190},
{customer:"AAA", product:"Flash", quarter:"Q3", revenue:420, cost:75},
{customer:"BBB", product:"ColdFusion", quarter:"Q1", revenue:240, cost:20},
{customer:"BBB", product:"Flex", quarter:"Q2", revenue:100, cost:20},
{customer:"BBB", product:"Dreamweaver", quarter:"Q3", revenue:270, cost:120},
{customer:"BBB", product:"Flash", quarter:"Q4", revenue:370, cost:70},
{customer:"CCC", product:"ColdFusion", quarter:"Q1", revenue:375, cost:120},
{customer:"CCC", product:"Flex", quarter:"Q2", revenue:420, cost:120},
{customer:"CCC", product:"Dreamweaver", quarter:"Q3", revenue:680, cost:220},
{customer:"CCC", product:"Flash", quarter:"Q4", revenue:570, cost:170}
]); 
private function creationCompleteHandler():void {
// You must initialize the cube before you 
// can execute a query on it.
      myMXMLCube.refresh();
// Create the OLAP query.
private function getQuery(cube:IOLAPCube):IOLAPQuery {
// Create an instance of OLAPQuery to represent the query. 
     var query:OLAPQuery = new OLAPQuery; 
// Get the row axis from the query instance.
     var rowQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.ROW_AXIS);
// Create an OLAPSet instance to configure the axis.
     var productSet:OLAPSet = new OLAPSet;
// Add the Product to the row to aggregate data 
// by the Product dimension.
     productSet.addElements(
cube.findDimension("ProductDim").findAttribute("Product").children);
// Add the OLAPSet instance to the axis.
     rowQueryAxis.addSet(productSet); 
// Get the column axis from the query instance, and configure it
// to aggregate the columns by the Quarter dimension. 
     var colQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.COLUMN_AXIS);
     var quarterSet:OLAPSet= new OLAPSet;
     quarterSet.addElements(
     cube.findDimension("QuarterDim").findAttribute("Quarter").children);
     colQueryAxis.addSet(quarterSet);
     return query;
} 
// Event handler to execute the OLAP query 
// after the cube completes initialization.
private function runQuery(event:CubeEvent):void {
// Get cube.
     var cube:IOLAPCube = IOLAPCube(event.currentTarget);
// Create a query instance.
     var query:IOLAPQuery = getQuery(cube);
// Execute the query.
     var token:AsyncToken = cube.execute(query);
// Setup handlers for the query results.
     token.addResponder(new AsyncResponder(showResult, showFault));
} 
// Handle a query fault.
private function showFault(result:Object, token:Object):void {
     Alert.show("Error in query.");
} 
// Handle a successful query by passing the query results to 
// the OLAPDataGrid control..
private function showResult(result:Object, token:Object):void {
     if (!result) {
          Alert.show("No results from query.");
     return;
     }
     myOLAPDG.dataProvider= result as OLAPResult;            
}        
 ]]>
</mx:Script>     
<mx:OLAPCube name="FlatSchemaCube" dataProvider="{flatData}" id="myMXMLCube"
complete="runQuery(event);">         
<mx:OLAPDimension name="CustomerDim">            
<mx:OLAPAttribute name="Customer" dataField="customer"/>
<mx:OLAPHierarchy name="CustomerHier" hasAll="true">
<mx:OLAPLevel attributeName="Customer"/>            
</mx:OLAPHierarchy>        
</mx:OLAPDimension>
<mx:OLAPDimension name="ProductDim">
<mx:OLAPAttribute name="Product" dataField="product"/>            
<mx:OLAPHierarchy name="ProductHier" hasAll="true">                
<mx:OLAPLevel attributeName="Product"/>
</mx:OLAPHierarchy>
</mx:OLAPDimension>
<mx:OLAPDimension name="QuarterDim">            
<mx:OLAPAttribute name="Quarter" dataField="quarter"/>
<mx:OLAPHierarchy name="QuarterHier" hasAll="true">
<mx:OLAPLevel attributeName="Quarter"/>
</mx:OLAPHierarchy>
</mx:OLAPDimension>         
<mx:OLAPMeasure name="Revenue"  dataField="revenue" aggregator="SUM"/>    
</mx:OLAPCube>
<mx:Panel title="OLAPDataGrid Control" layout="vertical" color="0xffffff"
borderAlpha="0.15" width="500" paddingTop="5" paddingRight="10"
paddingBottom="10" paddingLeft="10" horizontalAlign="center">
<mx:OLAPDataGrid id="myOLAPDG" color="0x323232" width="100%" height="100%"/>
</mx:Panel>
</mx:Application>

Write a comment

Powered by WP Hashcash