The Line Is the Easy Part: Building an Animated Line Chart in After Effects

Drawing an animated line chart in After Effects takes about ten minutes. Making it correct takes the rest of the day.

The line itself is a solved problem: build a path from your data and animate Trim Paths. Everything around it is where the time goes. The dot that should ride the tip, the "smooth" curve that invents data, the area fill that refuses to fill, the axis that needs sensible numbers. This post goes through each of those, then shows how aeChart handles them.

If your CSV isn't in After Effects yet, the CSV import guide covers that part, including the semicolon problem that bites everyone in Europe.

Building the line from data

Since After Effects CC 2018 you can build a path with an expression. Put this on the Path property of a shape layer:

f = footage("visitors.csv");
n = 12;
pts = [];
for (i = 0; i < n; i++) {
  x = linear(i, 0, n - 1, -700, 700);
  y = linear(parseFloat(f.dataValue([1, i])), 0, 5000, 300, -300);
  pts.push([x, y]);
}
createPath(pts, [], [], false)

Add a Stroke, add Trim Paths, animate End from 0 to 100, and you have a line drawing itself across the screen. Notice the hard-coded 12 and 5000. We'll come back to those, because they're where this falls apart.

Where an animated line chart gets hard

The dot at the tip

Almost every line chart animation has a dot riding the front of the line. The obvious way to place it is from the data: at 50% progress, put the dot halfway through the points.

That doesn't match the line. Trim Paths measures progress along the path's length, and a steep segment is longer than a flat one. Index-based progress gives every segment the same share of time. So the dot and the end of the line drift apart whenever the segments differ in length, which is always. You see it as a dot that floats ahead of the line on one stretch and gets left behind on the next.

You can work around it with pointOnPath() or by doing the length math yourself. Either way, it's not ten minutes anymore.

Smooth curves can lie

A smooth line looks more polished. It also overshoots. Give a standard Bézier smoothing three points like 10, 50, 52 and the curve will happily bulge above 52 between them, showing a peak that doesn't exist in your data. Near a zero baseline it can dip below zero, which is a fun conversation to have with a client whose revenue was never negative.

The proper fix is a monotone curve that never overshoots its data points. Writing tangent math for that inside an expression is… a project.

My take: Linear is the honest default. Stepped is right for values that change in jumps, like prices or interest rates. Smooth is fine when the vibe matters more than the exact peak, as long as the curve doesn't make things up.

Area charts and the fill that won't behave

An area chart sounds like a line chart plus a fill. Add a Fill to your trimmed line and you'll see the problem immediately: a fill on an open, trimmed path closes itself with a straight line from the trim end back to the start. You get a diagonal wedge across your chart instead of a fill down to the baseline.

So the area needs its own path: every point up to the current progress, an interpolated point at the tip, then two corners down at the baseline. Calculated every frame, in sync with the trimmed line. Or a track matte that reveals a static area shape, which works until the client wants the fill in a lighter tone of each line's colour, per line.

The axis needs nice numbers

Back to that hard-coded 5000. The Y maximum should come from the data, rounded up to a value that makes sense on an axis. Then the gridlines and axis labels need to be generated from the same number, at sensible steps. And if a value is in the thousands, the labels need separators in the right style.

Quick opinion while we're here: bars must start at zero, lines don't have to. A line chart of a stock that moves between 180 and 190 can zoom in. Just don't hide it.

More than one line

Comparing six products? Six paths, six colours, six dots, a legend, ideally a stagger so they don't all draw at once. And every one of them has to use the same Y scale, so each line's expression has to know about all the other columns. Change a column name in the CSV and you get to find out which expressions broke.

Points, markers and labels

Want a small marker at each data point that pops in as the line passes it? That's one more layer (or repeater trick) per point, timed against the trimmed length from the "dot at the tip" problem above. Value labels at each point? Same timing, plus collision handling when values are close together.

How aeChart builds a line chart

With aeChart:

  1. Choose CSV... The preview shows which column is the labels (your X axis, e.g. months) and which columns become lines.
  2. Type: Line. Check up to 6 series.
  3. Curve: Linear, Smooth or Stepped.
  4. Style: Line or Area. In Area mode, the space under each line fills in a lighter tone of its colour, and the fill grows together with the line.
  5. Pick your format (or all of them) and click Build Comp. The result is plain shape and text layers with a CHART CTRL null on top. Line-specific controls:
  • Line Style switches between Linear, Smooth and Stepped after the build.
  • Line Width and Dot Size.
  • Show Gridlines, Show Values, Show Axis Labels.
  • Duration, Delay, Stagger, Ease Style and Count Up for the values.
  • Series 1–6 Color. No keyframes, so you can change the duration or the curve style at any point without re-timing anything. And when next month's numbers come in, Update Data puts the new CSV in. Same rows and columns: done, the chart updates.

A last thing to watch

Line charts read best with more than a handful of points and fewer than a handful of lines. Six lines that cross each other twelve times is a plate of spaghetti, no matter who built it. If two of them are the story, give those two the strong colours and push the rest into a muted grey. Your audience will thank you, silently, by not scrolling away.

Previous
Previous

Every Slice Knows Every Other Slice: The Donut Chart in After Effects

Next
Next

"It's Just Rectangles": Animated Bar Chart in After Effects