Adobe Flex 3 ヘルプ

OLAPDataGrid コントロールの使用例

次の例は、OLAP データグリッドについての節で示されている OLAPDataGrid コントロールを作成するための完全なコードを示したものです。この例では、四半期別の製品売上高を集計します。この例では、売上高のレコードが次のフォーマットで記述されている dataIntro.as ファイルのフラットなデータを使用します。

data:Object = {
    customer:"AAA", 
    product:"ColdFusion",
    quarter:"Q1"
    revenue: "100.00" 
}

この例を実装するコードは次のとおりです。

<?xml version="1.0"?>
<!-- olapdatagrid/OLAPDG_Intro.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        creationComplete="creationCompleteHandler();">

    <mx:Script>
      <![CDATA[
        import mx.rpc.AsyncResponder;
        import mx.rpc.AsyncToken;
        import  mx.messaging.messages.ErrorMessage;
        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;
        
        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:ErrorMessage, token:Object):void {
            Alert.show(error.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;            
        }        
      ]]>
    </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:OLAPDataGrid id="myOLAPDG" width="100%" height="100%"/>
</mx:Application>

前の例で実行する SWF ファイルは以下のとおりです。

 

このページに新しいコメントが追加された場合に、電子メールでの通知を希望する。 | コメントレポート