2 Replies Latest reply on Jan 20, 2010 7:01 AM by brian274

    Help with OLAPDataGrid - all values coming back as NaN

    brian274

      Hi,

       

      I just stumbled across OLAPDataGrid, and found that it is a fairly good fit for the problem I was trying to solve.  I am still not sure that it fits exactly, as I have not done anything with OLAP before, I don't have all of the aggregation needs.  My problem is that the way I have it working right now, all of the rows display with the correct labels, but the values in the actual grid are always NaN.

       

      The server is already doing much of the aggregation.  The values I get back, I parse into objects that look like something like this:

       

      [

          {valueA: 100, valueB: "F", count: 20},

          {valueA: 100, valueB: "M", count: 10},

          {valueA: 90, valueB: "F", count: 83},

          {valueA: 90, valueB: "M", count: 76},

          {valueA: 80, valueB: "F", count: 11},

          {valueA: 80, valueB: "M", count: 48},

          {valueA: 70, valueB: "F", count: 100},

          {valueA: 70, valueB: "M", count: 11},

          {valueA: 60, valueB: "F", count: 19},

          {valueA: 60, valueB: "M", count: 48},

          {valueA: 50, valueB: "F", count: 21},

          {valueA: 50, valueB: "M", count: 9},

      ...

      ]

       

       

      I followed the example in the SDK documentation, and did like this:

       

      <mx:OLAPDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"

          width="100%" height="100%"

          >

       

          <mx:Script>

            <![CDATA[

             private var _facetCollection:ArrayCollection;

       

             [Bindable]

             public function get facetCollection():ArrayCollection {

                 return _facetCollection;

             }

       

             public function set facetCollection(value:ArrayCollection):void {

                 if (_facetCollection != value) {

                     _facetCollection = value;

                     _collectionChanged = true;

                     invalidateProperties();

                 }

             }

       

              override protected function commitProperties():void {

                 super.commitProperties();

                 if (_collectionChanged && facetCollection && cube) {

                     cube.refresh();

                 }

                 _collectionChanged = false;

              }

       

              // -------------------------------------------------------

              // OLAP methods

              // -------------------------------------------------------

       

              // Execute the OLAP query each time the cube is completes initialization

              private function runQuery(event:CubeEvent):void {

                  var cube:IOLAPCube = IOLAPCube(event.currentTarget);

                  var query:IOLAPQuery = getQuery(cube);

                  var token:AsyncToken = cube.execute(query);

                  token.addResponder(new AsyncResponder(showResult, showFault));

              }

       

              // Create the OLAP query

              private function getQuery(cube:IOLAPCube):IOLAPQuery {

                  var query:OLAPQuery = new OLAPQuery;

       

                  // Setup the row axis

                  var rowQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.ROW_AXIS);

                  var aSet:OLAPSet = new OLAPSet;

                  aSet.addElements(

                  cube.findDimension("ValueADim").findAttribute("A").children);

                  rowQueryAxis.addSet(aSet);

       

                  // Setup the column axis

                  var colQueryAxis:IOLAPQueryAxis = query.getAxis(OLAPQuery.COLUMN_AXIS);

                  var bSet:OLAPSet = new OLAPSet;

                  bSet.addElements(

                  cube.findDimension("ValueBDim").findAttribute("B").children);

                  colQueryAxis.addSet(bSet);

       

                  return query;     

              }

       

              private function showFault(result:Object, token:Object):void {

                  var event:ApplicationErrorEvent = new ApplicationErrorEvent(ApplicationErrorEvent.APPLICATION_FAULT);

                  event.message = "Error fetching data for 2 dimensional facet.";

                  dispatchEvent( event );

              }

       

              private function showResult(result:Object, token:Object):void {

                  if (!result) {

                  Alert.show("No results from query.");

                  return;

                  }

                  this.dataProvider = result as OLAPResult;

              }

            ]]>

          </mx:Script>

       

          <mx:OLAPCube name="CrossProductCube" dataProvider="{facetCollection}" id="cube" complete="runQuery(event);">

       

              <mx:OLAPDimension name="ValueADim">

                  <mx:OLAPAttribute name="A" dataField="valueA"/>

                  <mx:OLAPHierarchy name="AHier" hasAll="true">

                      <mx:OLAPLevel attributeName="A"/>

                  </mx:OLAPHierarchy>

              </mx:OLAPDimension>

       

              <mx:OLAPDimension name="ValueBDim">

                  <mx:OLAPAttribute name="B" dataField="valueB"/>

                  <mx:OLAPHierarchy name="BHier" hasAll="true">

                      <mx:OLAPLevel attributeName="B"/>

                  </mx:OLAPHierarchy>

              </mx:OLAPDimension>

       

              <mx:OLAPMeasure name="Count"

                  dataField="count"

                  aggregator="Max"/>

          </mx:OLAPCube>

       

      </mx:OLAPDataGrid>

       

      Not really sure where to start.  Any help would be appreciated!

       

      Thanks!