US and Worldwide: +1 (866) 660-7555
Results 1 to 7 of 7

Thread: Show values as percentage on stacked bar chart

  1. #1
    Join Date
    Apr 2010
    Posts
    149

    Default Show values as percentage on stacked bar chart

    Hi all,
    on stacked bar chart I set valuesVisible=True to show the values:

    stacked.png

    How it's possible to show the values as "value (percentage)":
    79 (47%)

    Thanks in advance for your time...

  2. #2
    Join Date
    Feb 2013
    Posts
    530

    Default

    This can be done in ValueFormat with Java script function.

    Some thing like
    function f(value){ sprintf('%d (%d)', value, calculatePercentage)}

    calculatePercentage = (SUMOFAllStacks/valueOfEachStack)*100

    This is just an idea.


    Quote Originally Posted by dadapenta View Post
    Hi all,
    on stacked bar chart I set valuesVisible=True to show the values:

    stacked.png

    How it's possible to show the values as "value (percentage)":
    79 (47%)

    Thanks in advance for your time...

  3. #3
    Join Date
    Feb 2013
    Posts
    530

    Default

    Hi Leao,

    have found this example from your site : http://jsfiddle.net/duarteleao/e2Qfd/

    Could you point us to store the summation value of stacks in a variable and use it in sprintf function in valueFormat property ?

    What is the difference b/w percenValueFormat & valueFormat properties for BarChart ?


    Thank you in Advance :-)

    Sadakar
    BI developer

  4. #4
    Join Date
    Mar 2012
    Posts
    642

    Default

    Hi,

    sorry for the late response.

    CCC actually already provides an easy way to show/obtain the percentage:

    Code:
    valuesMask: "{value} ({value.percent})"
    In code, you can access the value percentage (among values with the same category) like this:
    Code:
    function(scene) {
        var pctVar = scene.vars.value.percent;
        
        alert(pctVar.label);
    }
    Oh, and the difference is that one is used to calculate the "value"'s label while the other is used to calculate the "value.precent"'s label.
    Last edited by duarte.leao; 09-11-2014 at 05:41 PM.

  5. #5
    Join Date
    Feb 2013
    Posts
    530

    Default

    Thank you :-)

    It works greatly.

    Just attempting below code but it is not showing the popup with percentage values. Could you tell us where we can use this code ? (ValueFormat/Pre/Post-Exe/Change)
    function(scene) {
    var pctVar = scene.vars.value.percent;

    alert(pctVar.label);
    }

    Thank you again.
    :-)

  6. #6
    Join Date
    Mar 2012
    Posts
    642

    Default

    Ah, yes.

    The code I gave had an extension point/action handler signature. It cannot be used directly as the value of the PreExecution property, for example.
    It can, for example, be specified in the clickAction CDE property.

  7. #7
    Join Date
    Apr 2010
    Posts
    149

    Default

    thanks for your suggestions!
    great, as usual

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •