OLAP 控件使用


<?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"
creationComplete="creationCompleteHandler();"
minWidth="955" minHeight="600">

<!-- ====== Properties of parent ======================= -->
<s:layout>
<s:BasicLayout/>
</s:layout>

<!-- ====== MetaData =================================== -->

<!-- ====== Styles ===================================== -->

<!-- ====== Script ===================================== -->
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
import mx.events.CubeEvent;
import mx.olap.IOLAPAxisPosition;
import mx.olap.IOLAPCube;
import mx.olap.IOLAPElement;
import mx.olap.IOLAPMember;
import mx.olap.IOLAPQuery;
import mx.olap.IOLAPQueryAxis;
import mx.olap.OLAPQuery;
import mx.olap.OLAPResult;
import mx.olap.OLAPSet;
import mx.rpc.AsyncResponder;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
include "dataIntro.as"
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);
// Set up handlers for the query results.
token.addResponder(new AsyncResponder(showResult, showFault));
}
// Handle a query fault.
private function showFault(error:FaultEvent, token:Object):void {
Alert.show(error.fault.faultString);
}
// 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;
}

// Callback function that hightlights in green
// all cells with a value greater than or equal to 1000.
public function myStyleFunction(row:IOLAPAxisPosition, column:IOLAPAxisPosition,
value:Number):Object
{
if (value >= 120)
return {color:0x00FF00};
// Return null if value is less than 120.
return null;
}

]]>

</fx:Script>
<!-- ====== Declarations =============================== -->
<fx:Declarations>
<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>
</fx:Declarations>

<!-- ====== UI Components ============================== -->
<mx:OLAPDataGrid id="myOLAPDG" width="100%" height="100%"
styleFunction="myStyleFunction"/>
</s:Application>



dataIntro.as

[Bindable]
private var flatData:ArrayCollection = new ArrayCollection([
{customer:"A1", product: "ColdFusion", quarter:"Q1", revenue:1.00},
{customer:"A2", product: "ColdFusion", quarter:"Q1", revenue:1.00},
{customer:"A3", product: "ColdFusion", quarter:"Q1", revenue:1.00},
{customer:"A2", product: "Flex", quarter:"Q1", revenue:102.00},
{customer:"A3", product: "Photoshop", quarter:"Q1", revenue:103.00},
{customer:"A1", product: "ColdFusion", quarter:"Q2", revenue:110.00},
{customer:"A2", product: "Flex", quarter:"Q2", revenue:120.00},
{customer:"A3", product: "Photoshop", quarter:"Q2", revenue:130.00},
{customer:"A1", product: "ColdFusion", quarter:"Q3", revenue:100.00},
{customer:"A2", product: "Flex", quarter:"Q3", revenue:200.00},
{customer:"A3", product: "Photoshop", quarter:"Q3", revenue:300.00},
{customer:"A1", product: "ColdFusion", quarter:"Q4", revenue:100.10},
{customer:"A2", product: "Flex", quarter:"Q4", revenue:100.20},
{customer:"A3", product: "Photoshop", quarter:"Q4", revenue:100.30},
]);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值