Hitachi Vantara Pentaho Community Forums
Results 1 to 8 of 8

Thread: CDF Dinamyc build 2

  1. #1
    Join Date
    Jun 2007
    Posts
    476

    Default CDF Dinamyc build 2

    I'm posting a new thread because this problem has nothing to do with the past one.

    I'm building dynamically a DialChart but don't know how I'm supposed to name it: here's an example:
    Code:
    for(var i = 0; i < Dia; i++)
    {
        dialDef[i] = {
            width: 200,
            height: 180,
            chartType: "DialChart",
            backgroundColor: "#F3F3F3",
            BLABLABLA
            BLABLABLA
            BLABLABLA
            BLABLABLA
        };
        dialObj[i] = {
            name: "dial"+i+"",
            type: "dialComponent",
            chartDefinition: dialDef[i],
            htmlObject: "dial_"+i+"_obj",
            executeAtStart: true
        };
    }
    After this, I add it as follows:
    Code:
    var components = [];
    for (i = 0; i < Dia; i++)
    {
        components[i] = dialObj[i];
    }
    function load(){
        Dashboards.init(components);
    }
    load();
    The thing is that sometimes I get an IndexOutOffBounds and don't know how should I name the dialObject, the part where name : "dial"+i+"",

    Thanks
    Rodrigo
    Last edited by rhaces; 09-09-2009 at 01:39 PM.
    Rodrigo Haces
    TAM / Enterprise Architect
    Pentaho

  2. #2
    Join Date
    Jun 2007
    Posts
    476

    Default

    I think I found out why is this IndesxOutOfBounds, in my definition I have a query like this:

    Code:
    query: function(){
                var query = "SELECT sum(loaded) "+
                    "FROM LoadTable  "+
                    "WHERE DayOfWeek="+i+"";
                return query;
            }
    The problem is that "i" is not defined inside the query, just outside (the cycle I did) so I need to pass "i" to the query, how can I do this??? What I thought was to define a "global i" outside of the cyple like "var globali;" and then inside the cycle use globali=i; and in the query use globali instead of i, but it always takes the las i value. This is all the code I have:

    Code:
    var globi;
    for(var i = 0; i < 7; i++)
    {
        globi = i;
        dialDef[i] = {
            width: 200,
            height: 180,
            chartType: "DialChart",
            backgroundColor: "#F3F3F3",
            title: "myTitle",
            intervals: [25,50,75,100],
            queryType: 'sql',
            jndi: "MyJINDI",
            query: function(){
                var query = "SELECT sum(loaded) "+
                    "FROM LoadTable  "+
                    "WHERE DayOfWeek="+globi+"";
                return query;
            }
        };
        dialObj[i] = {
            name: "dial"+i+"",
            type: "dialComponent",
            chartDefinition: dialDef[i],
            htmlObject: "dial"+i+"_obj",
            executeAtStart: true
        };
    }
    Thanks for your help
    Last edited by rhaces; 09-09-2009 at 03:22 PM.
    Rodrigo Haces
    TAM / Enterprise Architect
    Pentaho

  3. #3
    Join Date
    Jun 2007
    Posts
    476

    Default

    No one??? I will have to create them manually and load them dynamically I guess!!!

    Hope anyone can help.
    Rodrigo Haces
    TAM / Enterprise Architect
    Pentaho

  4. #4
    Join Date
    Jul 2007
    Posts
    2,497

    Default

    Something on this lines has to work

    Code:
    var dials = [];
    
    for(var i = 0; i < 7; i++)
    {
        var dial = {
            name: "dial"+i+"",
            type: "dialComponent",
            chartDefinition:   {
            width: 200,
            height: 180,
            chartType: "DialChart",
            backgroundColor: "#F3F3F3",
            title: "myTitle",
            intervals: [25,50,75,100],
            queryType: 'sql',
            jndi: "MyJINDI",
            query: function(){
                var query = "SELECT sum(loaded) "+
                    "FROM LoadTable  "+
                    "WHERE DayOfWeek="+i+"";
                return query;
            }
        },
            htmlObject: "dial"+i+"_obj",
            executeAtStart: true
        };
    
        dials.push(dial)
    }
    
    Dashboards.init(dials)
    Pedro Alves
    Meet us on ##pentaho, a FreeNode irc channel

  5. #5
    Join Date
    Jun 2007
    Posts
    476

    Default

    The problem, as I understand, is that the function that calls the query is excecuted when the Dashboard.init, so "i" always takes the last value of i. I'm attaching my code, my 7 dials ALWAYS shows what I set as i=xx; at line 76. I've manage to do it like this after my for cycle and previous my Dashboard.init:

    Code:
    dials[0].chartDefinition.query=function(){var query = "SELECT (1) FROM FACT_CONTROL_ETL"; return query;};
    dials[1].chartDefinition.query=function(){var query = "SELECT (2) FROM FACT_CONTROL_ETL"; return query;};
    dials[2].chartDefinition.query=function(){var query = "SELECT (3) FROM FACT_CONTROL_ETL"; return query;};
    dials[3].chartDefinition.query=function(){var query = "SELECT (4) FROM FACT_CONTROL_ETL"; return query;};
    dials[4].chartDefinition.query=function(){var query = "SELECT (5) FROM FACT_CONTROL_ETL"; return query;};
    dials[5].chartDefinition.query=function(){var query = "SELECT (6) FROM FACT_CONTROL_ETL"; return query;};
    dials[6].chartDefinition.query=function(){var query = "SELECT (7) FROM FACT_CONTROL_ETL"; return query;};
    But as you can imagine, this could be a very hard to maintain code, and if I want i to be frrom 0 to 999 i will have to copy this lines 1,000 times...

    I'm wondering if I can set the function something like this:
    Code:
    query: function(var args[]){
        var query = "SELECT ("+arg[0]+") FROM FACT_CONTROL_ETL";
        return query;
    }
    And then tell the function/method that calls this function to pass i or something like that to this??

    Really I don't have that much time to go into the source code, learn it and then modify it.. or else I would have done it but maybe theres another solution.

    Thanks
    Attached Files Attached Files
    Rodrigo Haces
    TAM / Enterprise Architect
    Pentaho

  6. #6
    Join Date
    Jul 2007
    Posts
    2,497

    Default

    Oh, I see what you mean.

    That's easily solvable; on your case, query doesn't need to be a function. Use query: 'select ' + i + ' from ...'
    Pedro Alves
    Meet us on ##pentaho, a FreeNode irc channel

  7. #7
    Join Date
    Jun 2007
    Posts
    476

    Default

    Quote Originally Posted by pmalves View Post
    Oh, I see what you mean.

    That's easily solvable; on your case, query doesn't need to be a function. Use query: 'select ' + i + ' from ...'
    I can't use this because I need the function since I use a Listener to my process and if I dont use the function the listener doesnt work. What I tryed to do is do a kind of weird concatenation, something like this:

    Code:
    query: "SELECT ("+i+")"+function(){
        var query = " FROM FACT_CONTROL_ETL WHERE PROCESO='"+proceso+"'";
        return query;
    }
    Expectint that the return query would concatenate with my select ("+i+") but i doesn't do the job, watching the logs from the server, the query it sends to the db is: SELECT (1)function ()

    any other ideas??
    Rodrigo Haces
    TAM / Enterprise Architect
    Pentaho

  8. #8
    Join Date
    Jun 2007
    Posts
    476

    Default

    BUMP!!! Any ideas???
    Rodrigo Haces
    TAM / Enterprise Architect
    Pentaho

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.