在actionscript Flex 3中动态创建OLAP DATAGRID

时间:2012-07-12 15:57:48

标签: flex

我正在尝试在actionscript中构建OLAP Datagrid。有人有例子吗?

到目前为止,如果我使用mxml olapcube,那么当我尝试在actionscript中构建olapcube时,我的应用程序才能运行。

这是我的代码。

// SCRIPT

public var olapCube:OLAPCube = new OLAPCube();
private function loaded():void 
{
    //sends request.
    restRapport.url = "rapport_gridList.php?requete="+rapportRequete+"&champ1="+rapportChamp1+"&champ2="+rapportChamp2+"&champ3="+rapportChamp3+"&champ4="+rapportChamp4+"&champ5="+rapportChamp5+"&champ6="+rapportChamp6;
    restRapport.send();
    restRapport.addEventListener(ResultEvent.RESULT, olapFunct);
}

    private function olapFunct(evt:Event):void
    {           
        //OLAPCUBE.
        olapCube.name = 'cubeOLAP';
        olapCube.dataProvider = restRapport.lastResult.rapportlist.item;
        var dimensionArray:ArrayCollection =new ArrayCollection();

        //Dimensions.
        //Dimension 1
        var olapDimension1:OLAPDimension = new OLAPDimension();
        olapDimension1.name = "olapDimension1";
        var olapAttribute1:OLAPAttribute = new OLAPAttribute("champ1");
        olapAttribute1.name = rapportChamp1;
        var olapHierarchy1:OLAPHierarchy = new OLAPHierarchy();
        olapHierarchy1.hasAll = true;

        var olapLevel1:OLAPLevel = new OLAPLevel();
        olapLevel1.attributeName = rapportChamp1;

        olapHierarchy1.levels = new ArrayCollection([olapLevel1]); 

        olapDimension1.hierarchies = new ArrayCollection([olapHierarchy1]);

        olapDimension1.attributes = new ArrayCollection([olapAttribute1]);

        dimensionArray.addItem(olapDimension1);

        //Dimension 2
        var olapDimension2:OLAPDimension = new OLAPDimension();
        olapDimension2.name = "olapDimension2";
        var olapAttribute2:OLAPAttribute = new OLAPAttribute("champ2");
        olapAttribute2.name = rapportChamp2;
        var olapHierarchy2:OLAPHierarchy = new OLAPHierarchy();
        olapHierarchy2.hasAll = true;

        var olapLevel2:OLAPLevel = new OLAPLevel();
        olapLevel2.attributeName = rapportChamp2;

        olapHierarchy2.levels = new ArrayCollection([olapLevel2]); 

        olapDimension2.hierarchies = new ArrayCollection([olapHierarchy2]);

        olapDimension2.attributes = new ArrayCollection([olapAttribute2]);

        dimensionArray.addItem(olapDimension2);

        //Dimension 3
        var olapDimension3:OLAPDimension = new OLAPDimension();
        olapDimension3.name = "olapDimension3";
        var olapAttribute3:OLAPAttribute = new OLAPAttribute("champ3");
        olapAttribute3.name = rapportChamp3;
        var olapHierarchy3:OLAPHierarchy = new OLAPHierarchy();
        olapHierarchy3.hasAll = true;

        var olapLevel3:OLAPLevel = new OLAPLevel();
        olapLevel3.attributeName = rapportChamp3;

        olapHierarchy3.levels = new ArrayCollection([olapLevel3]); 

        olapDimension3.hierarchies = new ArrayCollection([olapHierarchy3]);

        olapDimension3.attributes = new ArrayCollection([olapAttribute3]);

        dimensionArray.addItem(olapDimension3);

        //Dimension 4
        var olapDimension4:OLAPDimension = new OLAPDimension();
        olapDimension4.name = "olapDimension4";
        var olapAttribute4:OLAPAttribute = new OLAPAttribute("champ4");
        olapAttribute4.name = rapportChamp4;
        var olapHierarchy4:OLAPHierarchy = new OLAPHierarchy();
        olapHierarchy4.hasAll = true;

        var olapLevel4:OLAPLevel = new OLAPLevel();
        olapLevel4.attributeName = rapportChamp4;

        olapHierarchy4.levels = new ArrayCollection([olapLevel4]); 

        olapDimension4.hierarchies = new ArrayCollection([olapHierarchy4]);

        olapDimension4.attributes = new ArrayCollection([olapAttribute4]);

        dimensionArray.addItem(olapDimension4);

        //Measure
        var measureArray:ArrayCollection =new ArrayCollection();

        //measure1
        var olapMesure1:OLAPMeasure = new OLAPMeasure();
        olapMesure1.dataField = rapportChamp5;
        olapMesure1.aggregator = "SUM";
        measureArray.addItem(olapMesure1);


        olapCube.dimensions = dimensionArray;
        olapCube.measures = measureArray;

        // You must initialize the cube before you 
    // can execute a query on it.
    olapCube.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 set1:OLAPSet = new OLAPSet;
    // Add the Product to the row to aggregate data 
    // by the Product dimension.
    set1.addElements(
        cube.findDimension("olapDimension1").findAttribute("olapAttribute1").children);
    // Add the OLAPSet instance to the axis.
    var set2:OLAPSet=new OLAPSet();
    set2.addElements(cube.findDimension("olapDimension2").findAttribute("olapAttribute2").children);
    rowQueryAxis.addSet(set2.crossJoin(set1));

    // 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 set3:OLAPSet= new OLAPSet;
    set3.addElements(
        cube.findDimension("olapDimension3").findHierarchy("olapHierarchy3").children);
    colQueryAxis.addSet(set3);

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

// MXML

    <mx:HTTPService id="restRapport" showBusyCursor="true" method="GET"/>

<!--
    <mx:OLAPCube name="FlatSchemaCube" 
        dataProvider="{restRapport.lastResult.rapportlist.item}" 
        id="myMXMLCube"
        complete="runQuery(event);">

        <mx:OLAPDimension name="olapDimension1">
            <mx:OLAPAttribute name="olapAttribute1" dataField="champ1"/>
            <mx:OLAPHierarchy name="olapHierarchy1" hasAll="true">
                <mx:OLAPLevel attributeName="olapAttribute1"/>
            </mx:OLAPHierarchy>
        </mx:OLAPDimension>

        <mx:OLAPDimension name="olapDimension2">
            <mx:OLAPAttribute name="olapAttribute2" dataField="champ2"/>
            <mx:OLAPHierarchy name="olapHierarchy2" hasAll="true">
                <mx:OLAPLevel attributeName="olapAttribute2"/>
            </mx:OLAPHierarchy>
        </mx:OLAPDimension>

        <mx:OLAPDimension name="olapDimension3">
            <mx:OLAPAttribute id="olapAttribute3" name="olapAttribute3" dataField="champ3"/>
            <mx:OLAPHierarchy name="olapHierarchy3" hasAll="true">
                <mx:OLAPLevel id="olapLevel3" attributeName="olapAttribute3"/>
            </mx:OLAPHierarchy> 
        </mx:OLAPDimension>

        <mx:OLAPMeasure name="olapMesure1"
            dataField="champ5" 
            aggregator="SUM"/>
    </mx:OLAPCube>
-->
    <mx:OLAPDataGrid id="myOLAPDG" width="800" height="600">
    </mx:OLAPDataGrid>

提前感谢您的帮助。

0 个答案:

没有答案