Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Cube Grid doesn't show up

    I'm trying to create a Cube Grid.

    Code:
      public CubeGrid advancedCube;
        VLayout mainLayout;
    
     public void onModuleLoad() {
     mainLayout = new VLayout();
    mainLayout.setWidth100();
    mainLayout.setHeight100();
    mainLayout.setMembersMargin(8);
    mainLayout.setLayoutMargin(10);
    
     if (SC.hasAnalytics()) {
                DataSource dS = DataSource.get("adb");
                DSRequest dSR = new DSRequest();
                dSR.setOperationId("cubeGrid");
                dSR.setTimeout(600000);
                dS.fetchData(new Criteria(), new DSCallback() {
                    public void execute(DSResponse dsResponse, Object o, DSRequest dsRequest) {
                        advancedCube = new CubeGrid();
                        if (SC.hasDrawing()) {
                            advancedCube.setEnableCharting(true);
                        }
                        advancedCube.setWidth100();
                        advancedCube.setHeight100();
                        advancedCube.setHideEmptyFacetValues(false);
                        advancedCube.setData(dsResponse.getData());
                        advancedCube.setShowCellContextMenus(true);
                        advancedCube.setRowFacets("ORIG", "DEST");
                        advancedCube.setColumnFacets("dates");
                        advancedCube.redraw();
                    }
                }, dSR);
    
    
                mainLayout.addMember(advancedCube);
                mainLayout.draw();
    } else {
                HTMLFlow htmlFlow = new HTMLFlow("<div class='explorerCheckErrorMessage'><p>This example is disabled in this SDK because it requires the optional " +
                        "<a href=\"http://www.smartclient.com/product/index.jsp\" target=\"_blank\">Analytics module</a>.</p>" +
                        "<p>Click <a href=\"http://www.smartclient.com/smartgwtee/showcase/#cube-analytics\" target=\"\">here</a> to see this example on smartclient.com</p></div>");
                htmlFlow.setWidth100();
                htmlFlow.draw();
            }
    }
    and adb.ds.xml file :

    Code:
    <DataSource ID="adb" table="adb" serverType="sql" dbName="jdbc/mdads" qualifyColumnNames="false">
        <fields>
            <field name="ORIG" type="text" required="false" length="3" title="Origin"/>
            <field name="DEST" type="text" required="false" length="3" title="Destination"/>
            <field name="DATES" type="number" required="false" title="Dates"/>
            <field name="SECURITY_ID" type="text" required="false" length="20" title="Customer Id"/>
            <!--<field name="BOOK_CLASS" type="text" required="false" length="1" title="Booking Class"/>-->
            <field name="DOMAIRL" type="text" required="false" length="2" title="Marketing Airline"/>
            <!--<field name="OPAIRL" type="text" required="false" length="3" title="Operating Airline"/>-->
            <field name="ORG_CNTRY_CD" type="text" required="false" length="3" title="Origin Country"/>
            <field name="DEST_CNTRY_CD" type="text" required="false" length="3" title="Destination Country"/>
            <field name="ORG_CTY_CD" type="text" required="false" length="3" title="Origin City"/>
            <field name="DEST_CTY_CD" type="text" required="false" length="3" title="Destination City"/>
            <field name="bookings" type="number" required="false" title="Bookings"/>
            <field name="fare" type="number" required="false" title="Fare"/>
            <field name="revenue" type="number" required="false" title="Revenue"/>
            <!--<field name="WACO" type="text" required="false" length="3" title="Origin Area"/>-->
            <!--<field name="WACD" type="text" required="false" length="3" title="Destination Area"/>-->
        </fields>
        <operationBindings>
            <operationBinding operationType="fetch" operationId="cubeGrid">
                <selectClause>
                    ORIG,DEST,dates, sum(pax_count) as bookings,round(sum(adb_revenue)/sum(pax_count),2) as fare,
                    sum(adb_revenue) as revenue
                </selectClause>
                <whereClause>security_id ='120' AND orig in ('BOM','DEL','CCU') and DEST IN ('MAA','AMD','COM') and dates between 200901 and
                    200903
                </whereClause>
                <groupClause>
                    ORIG,DEST,dates
                </groupClause>
            </operationBinding>
        </operationBindings>
        <!--<operationBinding operationType="fetch"-->
                          <!--whereClause="security_id ='120' AND orig='BOM' and dest='DEL' and dates=200901 and domairl='AI' "/>-->
    
    </DataSource>
    The query runs but I dont see anything on the screen. It's just plain white blank screen. Am I missing something. But if i put the sample from showcase it works fine.

    thanks.

    #2
    Is it mandatory to do cubeGrid.setdata() prior to adding it to another component.
    Because the following code simply renders cube grid undrawn.
    How do i debug the reasons why a component is undrawn ??

    Code:
    VLayout rLayout = new VLayout();
    CubeGrid cGrid = createCubeGrid();
     rLayout.addMember(cGrid);
    Code:
    public CubeGrid createCubeGrid() {
    
             final CubeGrid cubeGrid = new CubeGrid();
                //in order to enable charting, the Drawing module must be present
                if(SC.hasDrawing()) {
                    cubeGrid.setEnableCharting(true);
                }
                cubeGrid.setDataSource(DataSource.get("adb"));
                cubeGrid.setFetchOperation("cubeGrid");
                cubeGrid.setWidth100();
                cubeGrid.setHeight100();
                cubeGrid.setHideEmptyFacetValues(true);
                cubeGrid.setShowCellContextMenus(true);
                 DataSource dS = DataSource.get("adb");
                    DSRequest dSR = new DSRequest();
                    dSR.setEndRow(12);
                    dSR.setOperationId("cubeGrid");
                    dS.fetchData(new Criteria(), new DSCallback() {
                        public void execute(DSResponse response, Object o, DSRequest request) {
                            cubeGrid.setData(response.getData());
                        }
                    }, dSR);
    
                final NumberFormat numberFormat = NumberFormat.getFormat("0,000");
    
                cubeGrid.setCellFormatter(new CellFormatter() {
                    public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                        if (value == null) return null;
                        try {
                            return numberFormat.format(((Number) value).longValue());
                        } catch (Exception e) {
                            return value.toString();
                        }
                    }
                });
                cubeGrid.fetchData();
    
                cubeGrid.setRowFacets("ORIG", "DEST");
                cubeGrid.setColumnFacets("dates", "bookings");
    
                return cubeGrid;
        }
    But when I manually set data using cubeGrid.setData(...) it is drawn.

    Can somebody tell me how a cube Grid is supposed to be initiated when I need to create facets on the fly from the database result.

    Comment


      #3
      First, an obvious flaw: it doesn't make sense to call both cubeGrid.setData() and cubeGrid.fetchData().

      Beyond that, creating a cube from data fetched from the server is exactly the same as creating it directly. Just put all of your code for creating the cube into the DataSource.fetchData() callback. Before then, the cube has nothing to show, so there's no point in drawing it or adding it to any parent.

      Finally, as we told you off-forum:

      Please be sure to:
      1. look in the Developer Console for errors or warnings
      2. if you need further help, update the thread with what you see in the Developer Console as well as the data being provided to the cube
      3. provide the exact version you're using

      Comment


        #4
        Thanks for the response.

        In the advanced Cube Grid sample facet values have been harcoded with values like : Regions (North,South,West,East).

        I'm trying to create a cube grid and my table schema is :

        Origin Airport, Origin City, Origin Country, Origin Area, Destination , Destination City, Destination Country, Destination Area, Bookings, Month ,Year.

        I need to create a facet like Origin which is a tree. with the following relations:

        Origin Area
        |
        Origin Country
        |
        Origin City
        |
        Origin Airport

        The number of cities and airports in the world is huge to hardcode like in the sample. Also all data need not be fetched. Only based on user selected criteria a cube grid needs to be generated. Hence creation of Facet Values of Facets need to be dynamic.

        Is this possible.

        I'm using the nightly build version.

        Thanks.

        Comment


          #5
          If the number of airports is only a few thousand and you don't have a need to support IE6 (IE7+ should be fine) you could load the whole thing.

          Otherwise we would recommend using a load-on-demand TreeGrid to select portions of the Area/Country/City/Airport hierarchy, then have the user press a button to cause a cube to be built showing that subset of the hierarchy.

          Comment


            #6
            There are around 10,000 airports in the world. So tree approach makes more sense.

            But with the tree approach how to set the Facet Values??

            Comment


              #7
              So wee need to query seperately for setting Facets and then construct the cube grid. Data of the cube grid will be taken care by the datasource associated with cube grid. Did i understand it right ?

              Comment


                #8
                Right, that's the general technique for load on demand with dynamic facets.

                Comment


                  #9
                  What if the data in the table is not grouped at the level at which facets are created. Will it be automatically grouped when cell values are fetched.

                  Comment


                    #10
                    Don't really follow the question, but, tree facets fetch like other facets: in the Criteria, they provide a list of facetValues for which data is required. This may or may not map directly to your SQL table, if not, you can use a DMI to change the criteria in whatever way is required.

                    Comment


                      #11
                      I have sample rows like this:

                      BOM, DEL, 100 //(origin,destination,booking Count)
                      BOM, CCU, 200
                      DEL, CCU, 120
                      BOM, DEL, 110
                      BOM, CCU, 100

                      From the previous discussion, if I'm constructing a cub grid with facet Values as BOM,DEL for origin facet and DEL,CCU for destination facet. The cubeGrid needs to populate data after grouping it accordingly.

                      But your DMI approach seems to answer my question.

                      Comment


                        #12
                        Some doubts,

                        1) the "sum" FacetValue in the advanced Cube Grid sample is it directly calculated and put in the database on Cube Grid is calculating it on the fly based on data. I got this doubt because i see the following query:

                        Code:
                        SELECT DEST, DOMAIRL, ORG_CNTRY_CD, ORIG, DEST_CTY_CD, fare, SECURITY_ID, revenue, PAX_COUNT, DATES, DEST_CNTRY_CD, ORG_CTY_CD FROM adb WHERE (ORIG='CCU' AND ((DEST='sum') OR (DEST='IN')))
                        2) I have created facet values as discussed in the previous posts, but in the facet values,parent is a different column entry in the table ,

                        say.. in case of origin facet;
                        US (country-USA)
                        |
                        NYC(airport-new york)

                        US is mapped to column Origin Country in the table
                        where as NYC is mapped to Origin Airport in the table.

                        If you observe the sql that cubegrid generates it searches for "IN" in ORIG column only.

                        So how to differentiate this.

                        Basically i wanted to know how this whole cubeGRid query which it runs against can be customized according to facets.

                        3) though I set cubeGrid.setFetchOperationId(..) it seems to always query with default fetch ignoring the operitionBinding given.

                        Hope i'm clear !

                        Comment


                          #13
                          1) in the sample, it's pre-calculated in the dataset. You can either pre-calculate it as well or calculate it on the fly on the server. It can't be calculated client-side since load on demand means only part of the data is available.

                          2) you can modify dsRequest.criteria server-side to split the list of ORIG values between your two columns.

                          3) oops, you're correct. This has now been fixed and the fix will appear in the next nightly build. In the meantime you can just declare an operationBinding that has no operationId and the settings on that operationBinding (DMI et al) will be used by the cube.

                          Comment


                            #14
                            What handler should I set to configure the dsRequest as you mentioned.

                            Comment


                              #15
                              Take a look at the sections in the QuickStart Guide on DMI.

                              Comment

                              Working...
                              X