Home Tutorial Flex Flex4 Components OLAPDataGrid control in Flex4

 
 

Share on Google+Share on Google+
OLAPDataGrid control in Flex4
Posted on: June 19, 2010 at 12:00 AM
Advertisement
The full form of OLAP is online analytical processing. OLAPDataGrid control contains a large amount of data in many dimensions.

OLAPDataGrid control in Flex4:

The full form of OLAP is online analytical processing. OLAPDataGrid control contains a large amount of data in many dimensions. If you collect the information of product from different region, and from different customers in a two dimensional spreadsheet this data will be shown in OLAPDataGrid very easily. You will need a three thing to create a OLAPDataGrid:

1. OLAP Cube
2. OLAP schema
3. OLAP query

The tag of OLAPDataGrid is <mx:OLAPDataGrid>.

Example:

<?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"

minWidth="955" minHeight="600"

creationComplete="creationCompleteHandler();">

<fx:Declarations>

<!-- Define OALP schema -->

<mx:OLAPCube name="FlatProductSchemaCube"

dataProvider="{flatProductData}"

id="myProductCube"

complete="runQuery(event);">

<!-- Define Dimentions -->

<mx:OLAPDimension name="CustomerDimention">

<mx:OLAPAttribute name="Customer" dataField="customer"/>

<mx:OLAPHierarchy name="CustomerHier" hasAll="true">

<mx:OLAPLevel attributeName="Customer"/>

</mx:OLAPHierarchy>

</mx:OLAPDimension>

<mx:OLAPDimension name="ProductDimention">

<mx:OLAPAttribute name="Product" dataField="product"/>

<mx:OLAPHierarchy name="ProductHier" hasAll="true">

<mx:OLAPLevel attributeName="Product"/>

</mx:OLAPHierarchy>

</mx:OLAPDimension>

<mx:OLAPDimension name="QuarterDimention">

<mx:OLAPAttribute name="Quarter" dataField="quarter"/>

<mx:OLAPHierarchy name="QuarterHier" hasAll="true">

<mx:OLAPLevel attributeName="Quarter"/>

</mx:OLAPHierarchy>

</mx:OLAPDimension>

<!-- Define Measures -->

<mx:OLAPMeasure name="Revenue"

dataField="revenue"

aggregator="MAX"/>

</mx:OLAPCube>

</fx:Declarations>

<fx: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;

// Flat Product Data

[Bindable]

private var flatProductData:ArrayCollection = new ArrayCollection(

[

{customer:"X", product:"Monitor", quarter:"First", revenue:210, cost:25},

{customer:"X", product:"Processor", quarter:"Second", revenue:210, cost:25},

{customer:"X", product:"Mouse", quarter:"Third", revenue:250, cost:125},

{customer:"X", product:"Keyboard", quarter:"Fourth", revenue:430, cost:75},

{customer:"Y", product:"Monitor", quarter:"Second", revenue:125, cost:20},

{customer:"Y", product:"Processor", quarter:"Third", revenue:210, cost:20},

{customer:"Y", product:"Mouse", quarter:"Fourth", revenue:320, cost:120},

{customer:"Y", product:"Keyboard", quarter:"First", revenue:280, cost:70},

{customer:"Z", product:"Monitor", quarter:"Third", revenue:375, cost:120},

{customer:"Z", product:"Processor", quarter:"Fourth", revenue:430, cost:120},

{customer:"Z", product:"Mouse", quarter:"First", revenue:470, cost:220},

{customer:"Z", product:"Keyboard", quarter:"Second", revenue:570, cost:170},

{customer:"X", product:"Monitor", quarter:"Fourth", revenue:215, cost:90},

{customer:"X", product:"Processor", quarter:"First", revenue:210, cost:90},

{customer:"X", product:"Mouse", quarter:"Second", revenue:175, cost:190},

{customer:"X", product:"Keyboard", quarter:"Third", revenue:670, cost:75},

{customer:"Y", product:"Monitor", quarter:"First", revenue:175, cost:20},

{customer:"Y", product:"Processor", quarter:"Second", revenue:210, cost:20},

{customer:"Y", product:"Mouse",quarter:"Third", revenue:120, cost:120},

{customer:"Y", product:"Keyboard", quarter:"Fourth", revenue:310, cost:70},

{customer:"Z", product:"Monitor", quarter:"First", revenue:385, cost:120},

{customer:"Z", product:"Processor", quarter:"Second", revenue:340, cost:120},

{customer:"Z", product:"Mouse", quarter:"Third", revenue:470, cost:220},

{customer:"Z", product:"Keyboard", quarter:"Fourth", revenue:270, cost:170},

{customer:"X", product:"Monitor", quarter:"First", revenue:100, cost:25},

{customer:"X", product:"Processor", quarter:"Second", revenue:150, cost:25},

{customer:"X", product:"Mouse", quarter:"Third", revenue:200, cost:125},

{customer:"X", product:"Keyboard", quarter:"Fourth", revenue:300, cost:75},

{customer:"Y", product:"Monitor", quarter:"Second", revenue:175, cost:20},

{customer:"Y", product:"Processor", quarter:"Third", revenue:100, cost:20},

{customer:"Y", product:"Mouse", quarter:"Fourth", revenue:270, cost:120},

{customer:"Y", product:"Keyboard", quarter:"First", revenue:370, cost:70},

{customer:"Z", product:"Monitor", quarter:"Third", revenue:410, cost:120},

{customer:"Z", product:"Processor", quarter:"Fourth", revenue:300, cost:320},

{customer:"Z", product:"Mouse", quarter:"First", revenue:510, cost:220},

{customer:"Z", product:"Keyboard", quarter:"Second", revenue:620, cost:170},

{customer:"X", product:"Monitor", quarter:"Fourth", revenue:215, cost:90},

{customer:"X", product:"Processor", quarter:"First", revenue:210, cost:90},

{customer:"X", product:"Mouse", quarter:"Second", revenue:175, cost:190},

{customer:"X", product:"Keyboard", quarter:"Third", revenue:420, cost:75},

{customer:"Y", product:"Monitor", quarter:"First", revenue:240, cost:20},

{customer:"Y", product:"Processor", quarter:"Second", revenue:100, cost:20},

{customer:"Y", product:"Mouse", quarter:"Third", revenue:270, cost:120},

{customer:"Y", product:"Keyboard", quarter:"Fourth", revenue:370, cost:70},

{customer:"Z", product:"Monitor", quarter:"First", revenue:375, cost:120},

{customer:"Z", product:"Processor", quarter:"Second", revenue:420, cost:120},

{customer:"Z", product:"Mouse", quarter:"Third", revenue:680, cost:220},

{customer:"Z", product:"Keyboard", quarter:"Fourth", revenue:570, cost:170}

]);

// Refresh a OLAPCube

public function creationCompleteHandler():void {

myProductCube.refresh();

}

// Create Quary

public function getQuery(cube:IOLAPCube):IOLAPQuery {

// instance of OLAPQuery

var query:OLAPQuery = new OLAPQuery;

// instance of OLAPQueryAxis class for row

var rowQueryAxis:IOLAPQueryAxis =

query.getAxis(OLAPQuery.ROW_AXIS);

// instance of OLAPSet class

var productSet:OLAPSet = new OLAPSet;

productSet.addElements(

cube.findDimension("ProductDimention").findAttribute("Product").children);

rowQueryAxis.addSet(productSet);

// instance of OLAPQueryAxis class for column

var colQueryAxis:IOLAPQueryAxis =

query.getAxis(OLAPQuery.COLUMN_AXIS);

// instance of OLAPSet class

var quarterSet:OLAPSet= new OLAPSet;

quarterSet.addElements(

cube.findDimension("QuarterDimention").findAttribute("Quarter").children);

colQueryAxis.addSet(quarterSet);

return query;

}

// Execute the Quary

public function runQuery(event:CubeEvent):void {

var cube:IOLAPCube = IOLAPCube(event.currentTarget);

var query:IOLAPQuery = getQuery(cube);

var token:AsyncToken = cube.execute(query);

token.addResponder(new AsyncResponder(showResult, showFault));

}

// Query Fault

public function showFault(result:Object, token:Object):void {

Alert.show("Error in query.");

}

// Query Success

public function showResult(result:Object, token:Object):void {

if (!result) {

Alert.show("No results from query.");

return;

}

productDataGrid.dataProvider= result as OLAPResult;

}

]]>

</fx:Script>

<s:Panel title="OLAPDataGrid Example" width="385" height="210">

<mx:OLAPDataGrid id="productDataGrid"

x="11" y="11"

width="359" height="155"/>

</s:Panel>

</s:Application>

Output:

Running Application:

To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed.

Download this code

Advertisement

Related Tags for OLAPDataGrid control in Flex4:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 19, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com