1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | private function createMyCube():void { myCube = new OLAPCube(); myCube.addEventListener(CubeEvent.CUBE_COMPLETE, runQuery); // 创建 dim1 维度 var dim1:OLAPDimension = new OLAPDimension("Dim1"); // 对于 dim1 创建其 attributes var attr1:OLAPAttribute = new OLAPAttribute(chartXML.dim1label); attr1.dataField = "dim1"; attr1.displayName = chartXML.dim1label; dim1.attributes = new ArrayCollection([ attr1 ]); // 在维上创建用户定义的 hierarchy var dim1Hierarchy:OLAPHierarchy = new OLAPHierarchy("Dim1"); // 在 hierarchy 上定义 level var level1:OLAPLevel = new OLAPLevel(); level1.attributeName = chartXML.dim1label; dim1Hierarchy.levels = new ArrayCollection([ level1 ]); // 将创建好的 hierarchy 设置在 dim1 上 dim1.hierarchies = new ArrayCollection([ dim1Hierarchy ]); // 创建 dim2 维度 var dim2:OLAPDimension = new OLAPDimension("Dim2"); // 对于 dim2 创建其 attributes var attr2:OLAPAttribute = new OLAPAttribute(chartXML.dim2label); attr2.dataField = "dim2"; //attr2.displayName = chartXML.dim2label; dim2.attributes = new ArrayCollection([ attr2 ]); // 在维上创建用户定义的 hierarchy var dim2Hierarchy:OLAPHierarchy = new OLAPHierarchy("Dim2"); // 在 hierarchy 上定义 level var level2:OLAPLevel = new OLAPLevel(); level2.attributeName = chartXML.dim2label ; dim2Hierarchy.levels = new ArrayCollection([ level2 ]); // 将创建好的 hierarchy 设置在 dim2 上 dim2.hierarchies = new ArrayCollection([ dim2Hierarchy ]); // 创建 measure 度量信息 var measure:OLAPMeasure = new OLAPMeasure("Measure"); measure.dataField = "measure"; measure.aggregator = "SUM"; // dim1 维度,dim2 维度以及 measure 度量信息构成了整个 cube 的所有元素 myCube.elements = [ dim1, dim2, measure ]; } |
1 2 3 4 5 6 7 8 9 10 | private function runQuery(cubeEvent:CubeEvent):void { // 得到清单 6 创建好的 cube,cubeEvent 通过回调的方式将其返回 var cube:IOLAPCube = IOLAPCube(cubeEvent.currentTarget); // 创建查询实例 var query:IOLAPQuery = getQuery(cube); // 执行查询 var token:AsyncToken = cube.execute(query); // 设置回调函数来处理返回结果及错误信息 token.addResponder(new AsyncResponder(showResult, showFault)); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | private function getQuery(cube:IOLAPCube):IOLAPQuery { // 创建 OLAPQuery 实例来表示一次查询 var query:OLAPQuery = new OLAPQuery; // 得到此查询的横轴 var rowQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.ROW_AXIS); // 创建对应于横轴的 OLAPSet var productSet:OLAPSet = new OLAPSet; // 从 cube 中将关于产品维的聚集数据加入此 OLAPSet 中 productSet.addElements( cube.findDimension("Dim1").findAttribute(chartXML.dim1label).children); rowQueryAxis.addSet(productSet); // 得到此查询的纵轴 var colQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.COLUMN_AXIS); // 创建对应于纵轴的 OLAPSet var quarterSet:OLAPSet= new OLAPSet; // 从 cube 中将关于时间维的聚集数据加入此 OLAPSet 中 quarterSet.addElements( cube.findDimension("Dim2").findAttribute(chartXML.dim2label).children); colQueryAxis.addSet(quarterSet); return query; } |
1 2 3 4 5 6 7 8 | private function showResult(result:Object, token:Object):void { if (!result) { Alert.show("No results from query."); return; } myOLAPDG.dataProvider= result as OLAPResult; } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |