Menu

Tutorial 172: Easy & Powerful Graphs

Joe Clay | Apr 19, 2019

In this week's After Effects tutorial, we're making bar graphs. This time, we're going to use text animators to make them, which means we have access to text animators, so instead of being limited by shape layers, we have full access to animate each element with ranges. See Kyle Hamrick's #textperiments if you're unsure of how limitless text animators are.

This can be taken a lot further. You could even tie it to CSV data if you want to. But even as-is, this is a way to get accurate graphs using real data if you so choose. And to add a new data point, all you need to do is add a new number to the layer's name—which is pretty sweet.

I also forgot to mention one of the coolest aspects of this. It all lives on one layer so you can make it a preset! And don't forget to check out info on the spread operator from JS Tips. That totally beats what I was going to do—sorting a copy of the array and checking the first element.

Expression Code

Note that all of these require slider controls. You can see which ones you need to make assigned to variables in the following expressions.

This goes on the Source Text property.

var string = '.';
string.repeat(name.split(',').length);

This goes in text animator set to modify scale.

var x = effect("Bar Width")("Slider")/.195; //the height and width of this period is about 19.5px
var y = effect("Max Height")("Slider")/.195;
[x, y];

I think maybe my explanation for why I'm dividing the height and width sliders by the pixel size of the period may be weak. I want those sliders to work as pixel values but I need to use scale to accomplish that. So I divide the pixel value I want by the original pixel value. This gives me a ratio. It's going into scale, so I need percent. If something gets 2x larger, it needs to be 200% the size. So we multiply by 100. Make sense? I hope so.

I'm not sure exactly how to explain the .195 part mathematically. I guess it's sort of like we're in the middle of dividing by 19.5 so to multiply by 100, without actually doing it to the slider portion, we divide the part we're dividing by by 100. That multiplies the final value because we're dividing by a smaller number. Make sense? It's going to have to.

Apply the next expression to tracking in a text animator. I put this one in the same animator as the scale since they won't affect each other.

effect("Bar Width")("Slider")-19.5;

And finally, add another text animator with scale. Set scale to 100%, 0% and add this expression to an expression selector.

var values = name.split(',');
var maxValue = Math.max(...values);
(1-(values[textIndex-1]/maxValue))*100;

Recall that this runs for each character in the text and textIndex is the index of the character the expression is currently evaluating. That's it!

Grab the Project Files

Get the project file through our Gumroad Store. This project file contains all of the setups shown in the tutorial as well as some other graphic elements used in the final design. It also includes all of the expressions code shown. Unfortunately, some of the code we used is only available in the new JavaScript engine, so the project files are limited to AE CC 2019+ only.

If you're buying project files, consider becoming a Patron. At the $5/mo. tier, you get access to project files as they come out and some tutorials also come with additional BTS content showing more of the builds.

Get the project on Gumroad

Become a Patron

If you'd like to help support Workbench, check out our Patreon page. Thank you for even considering clicking this link to support what we're doing. We appreciate it. Patrons get all sorts of benefits, from additional files to early product releases depending upon the tier.

Check out our Patreon Today