Adobe Flex 3 Help

Creating a multidimensional axis in an OLAPDataGrid control

The OLAPDataGrid control displays information along two axes: row and column. However, limiting yourself to writing queries that return only two dimensions can restrict your ability to examine your data.

To allow you greater flexibility in displaying query results, the OLAPDataGrid control supports hierarchical display along its axis. The following image shows quarterly sales information, grouped by year, displayed in the columns of the OLAPDataGrid control.

Quarterly sales information, grouped by year, displayed in the columns of the OLAPDataGrid control

To create a multidimensional axis in the OLAPDataGrid control, you create two or more OLAPSet instances for the axis, and then combine the OLAPSet instances by doing a crossjoin or a union, as the following table describes:

Combination type

OLAPSet method

Description

Crossjoin

crossJoin()

Creates a crossjoin of two OLAPSet instances, where a crossjoin contains all possible combinations of the two sets. A crossjoin is also called a cross product of the members of the two different sets.

Union

union()

Creates a union of two OLAPSet instances.

In the following example, you create an OLAPSet instance for the year, and then crossjoin that set with the OLAPSet instance for quarter to create the OLAPDataGrid control shown in the previous image:

private function getQuery(cube:IOLAPCube):IOLAPQuery {
    var query:OLAPQuery = new OLAPQuery;

    var rowQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.ROW_AXIS);
    var productSet:OLAPSet = new OLAPSet;
    productSet.addElements(
        cube.findDimension("ProductDim").findAttribute("Product").children);
    rowQueryAxis.addSet(productSet);
            
    var colQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.COLUMN_AXIS);         
    var yearSet:OLAPSet= new OLAPSet;
    yearSet.addElements(
        cube.findDimension("TimeDim").findAttribute("Year").children);
    var quarterSet:OLAPSet= new OLAPSet;
    quarterSet.addElements(
        cube.findDimension("TimeDim").findAttribute("Quarter").children);
    colQueryAxis.addSet(yearSet.crossJoin(quarterSet));

    return query;       
}

The executing SWF file for the previous example is shown below:

Creating a slicer axis

An OLAP query can have three axes: row, column, and slicer. A slicer axis lets you reduce the size of the query results, often to reduce the dimensionality of the results from a dimension greater than two so that you can display the results. Another common use of a slicer axis is to aggregate data on a measure other than the default measure.

Creating a query using a nondefault measure

The following schema defines two measures for the points in the cube: Revenue and Cost. The first measure defined in the schema is the default measure, and it is the data that is aggregated by a query if you do not explicitly specify the measure.

<mx:OLAPCube name="FlatSchemaCube" 
    dataProvider="{flatData}" 
    id="myMXMLCube"
    complete="runQuery(event);">
     
    <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="MAX"/>
    <mx:OLAPMeasure name="Cost" 
        dataField="cost" aggregator="MIN"/>
</mx:OLAPCube>

To aggregate by the Cost measure, you create a slicer axis to explicitly specify the measure for the query, as the following example shows:

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;
    productSet.addElements(
        cube.findDimension("ProductDim").findAttribute("Product").children);
    rowQueryAxis.addSet(productSet);

    var colQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.COLUMN_AXIS);         
    var quarterSet:OLAPSet= new OLAPSet;
    quarterSet.addElements(
        cube.findDimension("TimeDim").findAttribute("Month").children);
    colQueryAxis.addSet(quarterSet);
 
    // Create the slicer axis. 
    var slicerQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.SLICER_AXIS);         
    // Create an OLAPSet instance to configure the axis.
    var costSet:OLAPSet= new OLAPSet;
    // Use OLAPDimension.findMember() to add the Cost measure.
    costSet.addElement(cube.findDimension("Measures").findMember("Cost"));
    slicerQueryAxis.addSet(costSet);

    return query;       
}

The executing SWF file for the previous example is shown below:

In this example, you use the keyword Measures to identify the measure dimension, and then use the OLAPDimension.findMember() method to access the Cost measure.

Using a slicer axis to reduce the dimensionality of the query result

The OLAPDataGrid control displays information in two dimensions along its row and column axis. However, to display product sales by region and by month, you require a three-dimensional display: one dimension each for product, region, and month.

For example, your data has the following format:

data:Object = {
    customer:"IBM", 
    country:"US",
    state:"MA",
    region:"NewEngland",
    product:"ColdFusion",
    year:2005,
    quarter:"Q1"
    month:"January",
    revenue: 12,575.00,
    cost: 500
}

The examples use the following OLAP schema to represent this data in an OLAP cube:

 <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="TimeDim">
            <mx:OLAPAttribute name="Year" dataField="year"/>
            <mx:OLAPAttribute name="Quarter" dataField="quarter"/>
            <mx:OLAPAttribute name="Month" dataField="month"/>
            <mx:OLAPHierarchy name="Time-Period" 
                hasAll="true">
                <mx:OLAPLevel attributeName="Year"/>
                <mx:OLAPLevel attributeName="Quarter"/>
                <mx:OLAPLevel attributeName="Month"/>
            </mx:OLAPHierarchy> 
        </mx:OLAPDimension>

        <mx:OLAPDimension name="GeographyDim">  
            <mx:OLAPAttribute name="Country" dataField="country"/>
            <mx:OLAPAttribute name="Region" dataField="region"/>
            <mx:OLAPAttribute name="State" dataField="state"/>
            <mx:OLAPHierarchy name="Country-Region-State" 
                hasAll="true">
                <mx:OLAPLevel attributeName="Country"/>
                <mx:OLAPLevel attributeName="Region"/>
                <mx:OLAPLevel attributeName="State"/>
            </mx:OLAPHierarchy> 
        </mx:OLAPDimension>

        <mx:OLAPMeasure name="Revenue" 
            dataField="revenue" 
            aggregator="SUM"/>
        <mx:OLAPMeasure name="Cost" 
         dataField="cost" 
         aggregator="SUM"/>
    </mx:OLAPCube>

You can use a slicer axis to filter the results of a query for display in two dimensions. In this example, you set the row axis to the region and the column axis to the month. You then define a slicer axis to specify the product as Flex so that you end up with a two-dimensional table of sales by region and month for Flex.

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;
    productSet.addElements(
        cube.findDimension("GeographyDim").findAttribute("Region").children);
    rowQueryAxis.addSet(productSet);

    var colQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.COLUMN_AXIS);         
    var quarterSet:OLAPSet= new OLAPSet;
    quarterSet.addElements(
        cube.findDimension("TimeDim").findAttribute("Month").children);
    colQueryAxis.addSet(quarterSet);

    // Create the slicer axis. 
    var slicerQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.SLICER_AXIS);         
    // Create an OLAPSet instance to configure the axis.
    var flexSet:OLAPSet= new OLAPSet;
    flexSet.addElement(
        IOLAPElement(cube.findDimension("ProductDim").findHierarchy("ProductHier").
        findLevel("Product").findMember("Flex").getItemAt(0)));
    slicerQueryAxis.addSet(flexSet);

    return query;       
}

The executing SWF file for the previous example is shown below:

You can specify more than one member for the slicer access. For example, if your cube contains information on different product such as Flex and Adobe® Flash®, you could create the two slicer axes as the following example shows:

// Create the slicer axis. 
var slicerQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.SLICER_AXIS); 

// Create an OLAPSet instance to configure the axis.
var sliceSet:OLAPSet= new OLAPSet;
sliceSet.addElement(IOLAPElement(cube.findDimension("ProductDim").
    findHierarchy("ProductHier").findLevel("Product").findMember("Flex").getItemAt(0)));

sliceSet.addElement(IOLAPElement(cube.findDimension("ProductDim").
    findHierarchy("ProductHier").findLevel("Product").findMember("Flash").getItemAt(0)));

slicerQueryAxis.addSet(sliceSet);

In this example, your query result would show sales of Flex and Flash for each region and month.

The executing SWF file for the previous example is shown below: