首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

OLAP 控件运用

2012-11-22 
OLAP 控件使用?xml version1.0 encodingutf-8?s:Application xmlns:fxhttp://ns.adobe.com/mxm

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},  ]);
1 楼 jack547155187 2010-11-14   都不知道是说什么的。加点说明吧

热点排行