OLAPDataGrid コントロールは、行と列の 2 本の軸によって情報を表示します。ただし、クエリの記述方法を、2 つのディメンションだけを返すものに限定してしまうと、データを確認する方法を制限することになる場合もあります。
クエリ結果をより柔軟に表示するために、OLAPDataGrid コントロールでは、軸に沿った階層の表示をサポートしています。次の図は、四半期ごとの売上高情報を年別にグループ化し、OLAPDataGrid コントロールの列に表示したものです。
OLAPDataGrid コントロールで多元軸を作成するには、軸に対して 2 つ以上の OLAPSet インスタンスを作成し、次の表で説明するように、複数の OLAPSet インスタンスをクロスジョイン(交差結合)またはユニオン(和結合)で結合します。
|
結合タイプ |
OLAPSet メソッド |
説明 |
|---|---|---|
|
クロスジョイン |
crossJoin() |
2 つの OLAPSet インスタンスのクロスジョインを作成します。クロスジョインには、2 つのセットで可能なすべての組み合わせが含まれます。クロスジョインは、2 つの異なるセットのメンバーのクロス積とも呼ばれます。 |
|
ユニオン |
union() |
2 つの OLAPSet インスタンスのユニオンを作成します。 |
次の例では、年に対して OLAPSet インスタンスを作成し、そのセットを四半期の OLAPSet インスタンスとクロスジョインして、前の図で示されている OLAPDataGrid コントロールを作成します。
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;
}
前の例で実行する SWF ファイルは以下のとおりです。
OLAP クエリには、行、列、およびスライサの 3 つの軸を含めることができます。スライサ軸を使用すると、クエリ結果のサイズを縮小することができます。主に、2 次元以上のディメンションから次元数を減少させるために使用し、結果を表示できるようにします。スライサ軸は、デフォルトメジャー以外のメジャーについてデータを集計する場合にも使用されます。
次のスキーマでは、キューブのポイントに対して、Revenue および Cost という 2 つのメジャーを定義しています。スキーマで最初に定義されているメジャーはデフォルトメジャーで、メジャーを明示的に指定しなかった場合に、クエリで集計されるデータとなります。
<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>
Cost メジャーに基づいて集計を行うには、次の例のようにスライサ軸を作成し、クエリに対してメジャーを明示的に指定します。
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;
}
前の例で実行する SWF ファイルは以下のとおりです。
この例では、キーワード Measures を使用してメジャーディメンションを特定し、OLAPDimension.findMember() メソッドを使用して Cost メジャーにアクセスしています。
OLAPDataGrid コントロールは、行と列の 2 次元で情報を表示します。ただし、地域別および月別に製品の売上高を表示するには、製品、地域、月という 3 つのディメンションが必要になり、3 次元表示が必要になります。
例えば、次のような形式のデータがあるとします。
data:Object = {
customer:"IBM",
country:"US",
state:"MA",
region:"NewEngland",
product:"ColdFusion",
year:2005,
quarter:"Q1"
month:"January",
revenue: 12,575.00,
cost: 500
}
この例は、次の OLAP スキーマを使用して、このデータを OLAP キューブで表現します。
<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>
クエリの結果を 2 次元で表示するには、スライサ軸を使用して結果をフィルタすることができます。この例では、行軸を地域に設定し、列軸を月に設定しています。さらにスライサ軸を定義して製品を Flex に指定し、Flex の地域別および月別の売上高を示す 2 次元のテーブルを作成します。
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;
}
前の例で実行する SWF ファイルは以下のとおりです。
スライサアクセスには、複数のメンバーを指定することができます。例えば、Flex や Adobe® Flash® など、様々な製品の情報がキューブに含まれている場合は、次の例で示されているように 2 本のスライサ軸を作成できます。
// 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);
この例では、各地域の月別の Flex および Flash の売上高が、クエリ結果で示されます。
前の例で実行する SWF ファイルは以下のとおりです。
このページに新しいコメントが追加された場合に、電子メールでの通知を希望する。 | コメントレポート