Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Dynamically Changing the Bar Chart Height

  1. #1

    Question Dynamically Changing the Bar Chart Height

    Hi,

    Can any body help me to change the height of the bar chart based on data receving using Java Script?

    Thanks in advance



    Hi

    Currently how am i doing is,

    I have Table Component also, so in in its Post Execution i am extracting the no. of records from the footer label of it as:

    function a()
    {
    var index1 = (window.document.getElementById('tbl_details_1_colTable_info').innerHTML.lastIndexOf('of')+2);
    var index2 = (window.document.getElementById('tbl_details_1_colTable_info').innerHTML.lastIndexOf('entries'));

    var total = (window.document.getElementById('tbl_details_1_colTable_info').innerHTML.substring(index1,index2).trim());
    Dashboards.fireChange('height_param',(total));
    }


    and in Pre-execution of Bar chart i have written like this :

    function f(){
    this.chartDefinition.height = 50 + (Dashboards.getParameterValue("height_param")*14);
    }


    can any body tell the exact way to find no. of records fetched without using the query execution again?

    Thankx & Regards,
    Murali
    Last edited by muralikrishna reddy; 01-02-2013 at 02:11 AM.

  2. #2

    Default

    Hi

    Currently how am i doing is,

    I have Table Component also, so in in its Post Execution i am extracting the no. of records from the footer label of it as:

    function a()
    {
    var index1 = (window.document.getElementById('tbl_details_1_colTable_info').innerHTML.lastIndexOf('of')+2);
    var index2 = (window.document.getElementById('tbl_details_1_colTable_info').innerHTML.lastIndexOf('entries'));

    var total = (window.document.getElementById('tbl_details_1_colTable_info').innerHTML.substring(index1,index2).trim());
    Dashboards.fireChange('height_param',(total));
    }


    and in Pre-execution of Bar chart i have written like this :

    function f(){
    this.chartDefinition.height = 50 + (Dashboards.getParameterValue("height_param")*14);
    }


    can any body tell the exact way to find no. of records fetched without executing the Query again to get the count?

    Thankx & Regards,
    ...

  3. #3
    Join Date
    Mar 2012
    Posts
    645

    Default

    The existing CCC "renderCallback" action is of no use in this situation, cause when it is called, the "height" option is already processed.

    The number of records, interpreted as being the number of categories, really depends on the specific format of the resultset (crosstab, seriesInRows).

    The following code, placed on the CDE chart component's post fetch should work:

    Code:
    function f(){
    
        function getCategoryCount(comp){
            var lastResults    = comp.query.lastResults();
            var isCrossTab     = comp.chartDefinition.crosstabMode;
            var isSeriesInRows = comp.chartDefinition.seriesInRows;
    
    
            if(isCrossTab && isSeriesInRows){
                return lastResults.metadata.length - 1;
            }
            
            var categIndex = (isCrossTab || isSeriesInRows) ? 0 : 1;
            return pv.uniq(lastResults.resultset.map(function(row){ 
                return row != null ? row[categIndex] : null;
            })).length;
        }
    
        this.chartDefinition.height = 50 + getCategoryCount(this) * 14;
    }

    [Edit 1 - 06/12/2013] Others have asked how to also know the number of "series" of a CDA data set.
    Here's a version that takes a cdaData object directly and returns the count of both:
    Code:
    function getSeriesAndCategoryCount(cdaData, options) {
        var isCrossTab     = (!options  || options.crosstabMode == null || !!options.crosstabMode);
        var isSeriesInRows = !!(options && options.seriesInRows);
    
        var resultset = cdaData.resultset;
    
        var categCount, seriesCount;
        if(isCrossTab) {
            // Assuming only one category column
            // Assume distinct, non-null, col and row values
            seriesCount = cdaData.metadata.length - 1;
            categCount  = resultset.length;
        } else {
            seriesCount = pv.uniq(resultset.map(function(row) { return row ? row[0] : null; })).length;
            categCount  = pv.uniq(resultset.map(function(row) { return row ? row[1] : null; })).length;
        }
    
        return isSeriesInRows ? [categCount, seriesCount] : [seriesCount, categCount];
    }
    Call it like this:
    Code:
    function f() {
         var cdaData = this.query.lastResults();
         var options  = this.chartDefinition;
    
         var seriesAndCategCount = getSeriesAndCategoryCount(cdaData, options);
         // ...
    }
    Last edited by duarte.leao; 12-06-2013 at 11:40 AM.

  4. #4

    Default

    yes,

    This is working well by placing in Post Fetch.
    Thank youduarte.leao

Tags for this Thread

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.