OLAPDataGrid control in Flex4


 

OLAPDataGrid control in Flex4

The full form of OLAP is online analytical processing. OLAPDataGrid control contains a large amount of data in many dimensions.

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

0

</mx:OLAPHierarchy>

</mx:OLAPDimension>

<!-- Define Measures -->

1

<mx:OLAPMeasure name="Revenue"

dataField="revenue"

aggregator="MAX"/>

2

</mx:OLAPCube>

</fx:Declarations>

<fx:Script>

3

<![CDATA[

import mx.rpc.AsyncResponder;

import mx.rpc.AsyncToken;

4

import mx.olap.OLAPQuery;

import mx.olap.OLAPSet;

import mx.olap.IOLAPQuery;

5

import mx.olap.IOLAPQueryAxis;

import mx.olap.IOLAPCube;

import mx.olap.OLAPResult;

6

import mx.events.CubeEvent;

import mx.controls.Alert;

import mx.collections.ArrayCollection;

7

// Flat Product Data

[Bindable]

private var flatProductData:ArrayCollection = new ArrayCollection(

8

[

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

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

9

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

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

0

{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},

1

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

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

2

{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},

3

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

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

4

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

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

5

{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},

6

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

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

7

{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},

8

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

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

9

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

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

0

{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},

1

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

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

2

{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},

3

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

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

4

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

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

5

{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},

6

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

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

7

{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}

8

]);

// Refresh a OLAPCube

public function creationCompleteHandler():void {

9

myProductCube.refresh();

}

// Create Quary

0

public function getQuery(cube:IOLAPCube):IOLAPQuery {

// instance of OLAPQuery

var query:OLAPQuery = new OLAPQuery;

1

// instance of OLAPQueryAxis class for row

var rowQueryAxis:IOLAPQueryAxis =

query.getAxis(OLAPQuery.ROW_AXIS);

2

// instance of OLAPSet class

var productSet:OLAPSet = new OLAPSet;

productSet.addElements(

3

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

rowQueryAxis.addSet(productSet);

// instance of OLAPQueryAxis class for column

4

var colQueryAxis:IOLAPQueryAxis =

query.getAxis(OLAPQuery.COLUMN_AXIS);

// instance of OLAPSet class

5

var quarterSet:OLAPSet= new OLAPSet;

quarterSet.addElements(

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

6

colQueryAxis.addSet(quarterSet);

return query;

}

7

// Execute the Quary

public function runQuery(event:CubeEvent):void {

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

8

var query:IOLAPQuery = getQuery(cube);

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

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

9

}

// Query Fault

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

0

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

}

// Query Success

1

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

if (!result) {

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

2

return;

}

productDataGrid.dataProvider= result as OLAPResult;

3

}

]]>

</fx:Script>

4

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

<mx:OLAPDataGrid id="productDataGrid"

x="11" y="11"

5

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

</s:Panel>

</s:Application>

6

Output:

Running Application:

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

Download this code

Ads