Skip to content
animorio
IT
All components

Stacked bar chart

Charts, HoverGSAP, CSS onlyMediumCompressed weight: Demo 7.8 KBGSAP 28 KBFreeDownload the zip

A dashboard card with twelve weeks of signups split by channel, in stacked bars of three tones of the same blue. The bars grow from the bottom one after another, on hover the week lights up and the others fade while a tooltip follows softly with the three values and the total, digits rolling; the legend takes a channel out and puts it back and the bars resettle on a short spring.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Stacked bar chart" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>The stacked bar chart with a tooltip</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- the card of an analytics dashboard: twelve weeks of signups stacked by channel. Hover a week and the column
         lights up while a tooltip follows with the three values; the legend takes a channel out and puts it back -->
    <section class="card" data-card aria-label="Signups by channel">
      <header class="card__head">
        <div>
          <h1 class="card__title">Signups by channel</h1>
          <p class="card__sub">Kestrin · last 12 weeks</p>
        </div>
        <button class="card__range" type="button" tabindex="-1" aria-hidden="true">
          12 weeks
          <svg viewBox="0 0 12 12" aria-hidden="true"><path d="M3 4.6 6 7.6l3-3"></path></svg>
        </button>
      </header>

      <div class="total">
        <p class="total__num" data-total aria-live="polite"></p>
        <p class="total__delta" data-delta>
          <svg viewBox="0 0 12 12" aria-hidden="true"><path d="M3 8.4 8.4 3M4.4 3h4v4"></path></svg>
          <span data-delta-num>+12.4%</span>
        </p>
        <p class="total__vs">vs previous 12 weeks</p>
      </div>

      <div class="legend" data-legend role="group" aria-label="Channels"></div>

      <div class="chart" data-chart>
        <div class="chart__grid" aria-hidden="true">
          <span></span><span></span><span></span><span></span>
        </div>
        <div class="chart__bars" data-bars></div>
        <div class="tip" data-tip aria-hidden="true">
          <p class="tip__week" data-tip-week></p>
          <div class="tip__mix" data-tip-mix><i></i><i></i><i></i></div>
          <div class="tip__rows" data-tip-rows></div>
          <p class="tip__total"><span>Total</span><b data-tip-total></b></p>
        </div>
      </div>
      <div class="axis" data-axis aria-hidden="true"></div>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2 19.2 11l-6.3 1.6-3.3 5.9Z"></path></svg>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

23 values to change

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Stacked bar chart” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

On a very light grey background, in the middle, a white card with wide corners: Signups by channel, below it Kestrin · last 12 weeks and on the right a 12 weeks pill. The twelve week total is big, with tabular digits, next to it a green +12.4% pill with a drawn arrow and vs previous 12 weeks in grey. Below, the legend: three pills Organic, Paid and Referral, each tinted in its tone with a thin check. Then the chart: four grid lines, twelve columns of bars stacked in three segments of blue, the darkest at the bottom, parted by a white hairline with the top segment rounded, and the week dates underneath, every other one. On opening the bars grow from the bottom one after another with a small bounce and the total rolls up to its value. A fake pointer runs over the weeks: the column under it rises two pixels and takes a pale blue track, the others fade, its date is written, and a white tooltip follows softly with the week, a small proportion bar, the three values and the total, digits rolling from one week to the next. Then it presses Paid: the pill turns into an outline, the check disappears, the middle segment closes in every bar and the bars stretch to fill the height, starting from the nearest week; the total rolls down. It runs over the weeks again, puts Paid back and everything resettles; at the end the bars sink and the round starts again.

How it works

Bars made of three segments

Each week is a flex column with column-reverse and three coloured i elements inside, one per channel: the first sits at the bottom. Heights are in pixels, the value times the chart’s scale, that is the usable height divided by the tallest visible week; the white hairline between segments is a two pixel margin that only exists between visible segments.

The growth

A timeline takes each segment from zero to its height in GROW seconds with back.out, staggering columns by STAGGER and the segments of one column by seven hundredths: the column grows from the bottom, one channel after another.

Rolling digits

Every digit of the total and the tooltip is a column of ten numbers ten lines tall, shut in a window one line tall; GSAP moves it by yPercent minus ten per digit with power3.out, the units a moment before the tens. The commas stay still.

The tooltip that follows

On hover the column is found from the pointer’s x; the tooltip goes to the right of the column, or to the left if there is no room, and two quickTo take it there in TIP_LAG seconds, so it glides instead of jumping. The other columns drop to DIM opacity.

The legend

A click on a pill flips the channel, recomputes every height and the scale and animates them with back.out starting from the nearest week; the last visible channel cannot be switched off and its pill gives a small no. The autopilot is a timeline with repeatRefresh, so the fake pointer’s positions are worked out again on every round.

Values to change

NameFileDefaultWhat it changes
TITLEscript.jsSignups by channelThe card’s title.
DELTAscript.js+12.4%The change next to the total.
STAGGERscript.js0.045The delay between one bar and the next as they grow.
GROWscript.js0.7The seconds a bar takes to grow.
DIMscript.js0.38How visible the other weeks stay on hover.
BOUNCEscript.js1.25How much the bars bounce as they resettle.
TIP_LAGscript.js0.32How long the tooltip takes to catch the pointer, in seconds.

Try them in the Playground

When to use it

For a SaaS product’s dashboard, the stats of an online shop or an app, a marketing panel: wherever a number has to be split into its parts and read week by week.

On phones

The card takes almost the full width, the chart is sized on the screen’s height and the vs previous 12 weeks line is hidden; a tap on a column does what hovering does and a tap outside closes the tooltip.

With reduced motion

The bars are already at their height, without growing; the tooltip stays open on the last week, moves without gliding and the digits change without rolling; the legend changes the bars at once.

Pitfalls

  • The scale is worked out on the tallest visible week: taking a channel out makes the bars stretch and fill the height, instead of staying low with half the chart empty.
  • The hairline between segments is a margin: it has to go on the hidden segment too, or a two pixel gap stays where the channel no longer is.
  • Rolling digits rebuild their columns only when the number’s shape changes (how many digits, where the comma is); otherwise they roll from the previous value.
  • The fake pointer’s positions are functions and the timeline has repeatRefresh: if the window changes size, on the next round the pointer goes to the right columns.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 7.8 KB; the libraries: GSAP 28 KB.

Testing

Tested on 25 October 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All components