Hitachi Vantara Pentaho Community Forums
Results 1 to 8 of 8

Thread: Barchart values as percentages

  1. #1

    Default Barchart values as percentages

    Hey Everyone, I was wondering if there is a way to display a barcharts values as percents rather than the actual values. I know the pie charts have an advanced property called valuesLabelStyle and was wondering if the bar charts had something similar? If not is there a way to do this using Javascript. If so would you be able to help me out with a javascript example? I have still not been able to find much documentation around the variables and their attributes that are in use in a dashboard. Thanks a bunch.

  2. #2
    Join Date
    Jan 2013
    Posts
    135

    Default

    There is advanced property - ValuesMask - you can use {value} or {value.percent} or combination of them {value} ({value.percent}).

  3. #3

    Default

    Thanks for the suggestion but when I use the {value.percent} in the value mask, the values are empty, when I use {value}({value.percent}) I get the value with empty parentheses next to it, for example 43(). However, I was able to get this done using MDX in the following way.

    I first compute new measures as the frequency of one of the dimensions values and divide it by the frequency of all the dimensions values and multiply the result by 100, and than use my new measures as the columns. I can then put the value mask of {value}% on them and they are displayed properly

    With
    MEMBER [Measures].[Strongly Disagree] AS
    (([var145.Code].[1],[Measures].[Frequency])/([var145.Code].[All var145.Codes],[Measures].[Frequency])*100),
    FORMAT_STRING='Percent'
    MEMBER [Measures].[Disagree] AS
    (([var145.Code].[2],[Measures].[Frequency])/([var145.Code].[All var145.Codes],[Measures].[Frequency])*100),
    FORMAT_STRING='Percent'
    MEMBER [Measures].[Neither Agree Nor Disagree] AS
    (([var145.Code].[3],[Measures].[Frequency])/([var145.Code].[All var145.Codes],[Measures].[Frequency])*100),
    FORMAT_STRING='Percent'
    MEMBER [Measures].[Agree] AS
    (([var145.Code].[4],[Measures].[Frequency])/([var145.Code].[All var145.Codes],[Measures].[Frequency])*100),
    FORMAT_STRING='Percent'
    MEMBER [Measures].[Strongly Agree] AS
    (([var145.Code].[5],[Measures].[Frequency])/([var145.Code].[All var145.Codes],[Measures].[Frequency])*100),
    FORMAT_STRING='Percent'

    SELECT
    NON EMPTY {[Measures].[Strongly Disagree],[Measures].[Disagree],[Measures].[Neither Agree Nor Disagree],[Measures].[Agree],[Measures].[Strongly Agree]} ON COLUMNS,
    NON EMPTY {Hierarchize({[var003.Value].[Value].Members})} ON ROWS
    FROM [cube]

  4. #4
    Join Date
    Mar 2012
    Posts
    645

    Default

    Hi decarlo,

    the percentage variable is only calculated/filled when the chart is stacked. That's why you get it blank.

    Maybe this is the same question I just answered in pentaho-br? If not, I'll just repeat the answer here ;-)

  5. #5
    Join Date
    Mar 2012
    Posts
    645

    Default

    Decided to post the answer I talked about anyway, for anyone else who needs this.

    Code:
    label_text: function(scene) {
        // Get a Data object grouped in inverse order: Series > Category
        // (the panel uses a Data object grouped in order: Category > Series)
        var invData = this.panel.visibleData({inverted: true});
    
        // The series and category of this scene.
        var series = scene.vars.series.value;
        var categ = scene.vars.category.value;
    
        // Get from invData, the inverse group that corresponds to this scene:
        var invGroup = invData.child(series).child(categ);
    
        // Calculate the percentage:
        var pctOverCategs = invGroup.dimensions("value")
            .percentOverParent();
    
        return (100 * pctOverCategs).toFixed(1);
    }
    


    The following fiddle contains a similar working example: http://jsfiddle.net/duarteleao/WACPb/.

  6. #6
    Join Date
    Nov 2013
    Posts
    11

    Default

    Hi there,

    I also have the same problem, but did not understand the answer. Where should I put that piece of code?

  7. #7
    Join Date
    Mar 2012
    Posts
    645

    Default

    Hi,

    "label_text" is an extension point. Due to the size of the function, you'd specify it directly in code. In "postFetch", for example. Read more here.

  8. #8

    Default

    This thread solved my issue Thanks all!

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.