Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Animating percentage bars in a chart

  • Animating percentage bars in a chart

    Posted by Sergio Pol on July 13, 2012 at 5:08 pm

    Hello I have an animated chart project that I need automated for regular editing. Basically my chart consists of a bar depicting 100% of certain stat that it’s divided by 4 segments.

    What I want is a script that enables me to type the correct value of each segment and it calculates the size of them, assigns those values to their relative text representations with the % symbol attached after the number.

    Would it be an absurd amount of work?

    I tried having a slider control on each segment layer controlling its width and linking that value to the text layer but still I’d need to manually place each segment so they start at the end of the previous one. Additionally this process generates some problems: The numeric value depicted by the text will not show rounded which I don’t want. It will kill the “%” symbol which is needed in the graph.

    Sergio Pol replied 14 years, 1 month ago 3 Members · 9 Replies
  • 9 Replies
  • Dan Ebberts

    July 13, 2012 at 6:13 pm

    I would set the anchor point of the bars to the right edge and add a Slider Control to each bar layer. Then I’d use a scale expression like this:

    w = effect(“Slider Control”)(“Slider”);
    [w,100]

    For the corresponding text layer, I’d use a position expression like this (assumes the layer is positioned properly in y):

    margin = 10;
    L = thisComp.layer(“bar 1”);
    x = L.transform.position[0] – L.width*L.transform.scale[0]/100;
    [x+margin,value[1]]

    And a Source Text expression like this:

    s = thisComp.layer(“bar 1”).effect(“Slider Control”)(“Slider”);
    Math.round(s) + “%”

    Dan

  • Dan Ebberts

    July 13, 2012 at 6:23 pm

    Oh yeah, I forgot–assuming that the right-most bar is layer “bar 1”, bar 2 would have this position expression:

    L = thisComp.layer(“bar 1”);
    x = L.transform.position[0] – L.width*L.transform.scale[0]/100;
    [x,value[1]]

    bar 3 would refer to bar 2, etc.

    Dan

  • Sergio Pol

    July 13, 2012 at 7:26 pm

    Wow I wouldn’t reach this in a million years with my almost non-existing knowledge on the subject. Thank you very much Dan. I’m going to try it right away and come back here to report how it went.

  • Sergio Pol

    July 13, 2012 at 8:23 pm

    Hi Dan, your script is superb!! I had to do minor tweaking since the bars come from left but it was nothing in relation to the work behind your code. I have only one more request. How could I specify a determine size for the “%” symbol? Thanks!!!

  • Dan Ebberts

    July 13, 2012 at 8:45 pm

    You could add a scale Animator to the text, then add an Expression Selector, delete the Range Selector, adjust the Animator’s Scale amount down to where you’re happy with the size of the last character (%), and finally, replace the default expression in the Expression Selector’s Amount property with this:

    if (textIndex == textTotal)100 else 0

    Dan

  • Sergio Pol

    July 13, 2012 at 9:22 pm

    Made it!! You’re amazing Dan (I had to delete many bad words describing how amazing I think you are), is there anything you can’t do in AE? Thanks so much!!

  • Sergio Pol

    July 13, 2012 at 9:25 pm

    Is there a way of reducing the space between the number and the “%”? I’m a little uncomfortable with it. Sorry for bothering you this much.

  • Kevin Camp

    July 13, 2012 at 9:32 pm

    from the text ‘animator’ add menu (the same menu that you selected the expression selector from) add a tracking property and set the tracking amount as needed.

    since the same animator already has an expression selector on it that is effecting only the last character in the string, the tracking property on the same animator will effect only the last character too.

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

  • Sergio Pol

    July 13, 2012 at 9:33 pm

    Thank you Kevin

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy