Animation
How fast a chart builds.
Speed
Each element takes --tablechart-animation-element-duration, the next one starts after --tablechart-animation-stagger of that time, and if the whole chart would take longer than --tablechart-animation-max, the starts move closer together.
.slow {
--tablechart-animation-element-duration: 0.9s;
--tablechart-animation-stagger: 0.5;
}
| Spring | 58 |
|---|---|
| Summer | 72 |
| Autumn | 70 |
| Winter | 41 |
<figure class="slow" data-chart="column">
<table>
<tbody>
<tr><th>Spring</th><td>58</td></tr>
<tr><th>Summer</th><td>72</td></tr>
<tr><th>Autumn</th><td>70</td></tr>
<tr><th>Winter</th><td>41</td></tr>
</tbody>
</table>
</figure>
| Variable | Sets |
|---|---|
--tablechart-animation-speed |
Faster or slower than the defaults of each chart type, as a factor: 1.25 is a quarter faster, 0.8 is slower. Every time is divided by it, also an element time or a maximum you set, so the chart types keep their own differences. The default is 1. |
--tablechart-animation-element-duration |
The time that one element (a bar, column, point or slice) transitions: 0.4s by default. |
--tablechart-animation-stagger |
When the next element starts. It is a ratio of the --tablechart-animation-element-duration: 0.25 by default. At 1, each element starts when the one before it is finished. At 0, all elements start together. |
--tablechart-animation-min |
The shortest a whole chart takes: 0.5s by default. If a chart would end sooner, its elements and their starts slow down together until it takes this long, so the stagger keeps its share. If the minimum is longer than the maximum, the maximum wins. |
--tablechart-animation-max |
The longest a whole chart may take to build: 2s by default. It is a ceiling, never a target: a small chart is not slowed down. Above it, the starts move closer together; each element keeps its own time. A waterfall shortens its columns instead, so they keep their order. Numbers fade in for at most a quarter of the maximum, and at most 0.6s. |
--tablechart-animation-ease |
The easing of bars, donuts, and lines and areas that grow: ease-in-out by default, slow at the start and the end. A line that sweeps does so at an even speed. |
--tablechart-annotation-duration |
How long an annotation line takes: 0.6s by default. |
These are CSS variables, so they can be set on a chart, a section or a whole page. Set on a section, the maximum holds for each chart in it.
If you want to try these settings with sliders on several chart types, and copy the CSS, see the Animation playground.
Few or many columns
A chart builds in 0.5s to 2s, however many columns or other elements it has. Each column takes 0.4s and the next one starts 0.1s later, so 2 columns take 0.5s and 10 take 1.3s. From about 18 columns, the starts move closer together, so the chart stays within the maximum, 2s. If a chart would end before the minimum, its columns and their starts slow down together. With a stagger of 0, all columns then grow together in 0.5s. A number comes in when its column is nearly grown.
| Spring | 58 |
|---|---|
| Summer | 72 |
| Autumn | 70 |
| Winter | 41 |
| 1 | 20 |
|---|---|
| 2 | 57 |
| 3 | 34 |
| 4 | 71 |
| 5 | 48 |
| 6 | 25 |
| 7 | 62 |
| 8 | 39 |
| 9 | 76 |
| 10 | 53 |
| 11 | 30 |
| 12 | 67 |
| 13 | 44 |
| 14 | 21 |
| 15 | 58 |
| 16 | 35 |
| 17 | 72 |
| 18 | 49 |
| 19 | 26 |
| 20 | 63 |
| 21 | 40 |
| 22 | 77 |
| 23 | 54 |
| 24 | 31 |
| 25 | 68 |
| 26 | 45 |
| 27 | 22 |
| 28 | 59 |
| 29 | 36 |
| 30 | 73 |
Waterfalls
A waterfall grows column by column, like a column chart, but its stagger is 2.4 times that of other charts: 0.6 by default. Each column starts when the one before it is nearly done, so they come one after the other without a pause. Its connector draws as the next column starts. If the whole chart would take longer than the maximum, the columns get shorter, so they keep coming one after the other.
If you want a waterfall to build differently, set --tablechart-waterfall-stagger-factor. At 1, a waterfall builds like a column chart. The factor multiplies --tablechart-animation-stagger, so if you change the stagger of all charts, a waterfall follows.
| Picked | 74.5 |
|---|---|
| Windfalls | 28.2 |
| Bruised | -16.1 |
| Peelings | -13.3 |
| Pressed | 73.3 |
<figure data-chart="waterfall">
<table>
<tbody>
<tr data-kind="total"><th>Picked</th><td>74.5</td></tr>
<tr><th>Windfalls</th><td>28.2</td></tr>
<tr><th>Bruised</th><td>-16.1</td></tr>
<tr><th>Peelings</th><td>-13.3</td></tr>
<tr data-kind="total"><th>Pressed</th><td>73.3</td></tr>
</tbody>
</table>
</figure>
With a lower stagger, the columns overlap more. At 1, each column waits until the one before it is finished.
.overlap {
--tablechart-animation-stagger: 0.25;
}
| Picked | 74.5 |
|---|---|
| Windfalls | 28.2 |
| Bruised | -16.1 |
| Peelings | -13.3 |
| Pressed | 73.3 |
<figure class="overlap" data-chart="waterfall">
<table>
<tbody>
<tr data-kind="total"><th>Picked</th><td>74.5</td></tr>
<tr><th>Windfalls</th><td>28.2</td></tr>
<tr><th>Bruised</th><td>-16.1</td></tr>
<tr><th>Peelings</th><td>-13.3</td></tr>
<tr data-kind="total"><th>Pressed</th><td>73.3</td></tr>
</tbody>
</table>
</figure>
If you want to build a waterfall at one speed instead, see Grow or sweep.
Donuts
A donut slice is one element, like a bar: it takes the element time, and the next slice starts after the stagger. So a big slice turns faster than a small one.
| Elstar | 42 |
|---|---|
| Jonagold | 28 |
| Braeburn | 18 |
| Gala | 12 |
<figure data-chart="donut">
<table>
<tbody>
<tr><th>Elstar</th><td>42</td></tr>
<tr><th>Jonagold</th><td>28</td></tr>
<tr><th>Braeburn</th><td>18</td></tr>
<tr><th>Gala</th><td>12</td></tr>
</tbody>
</table>
</figure>
With a stagger of 1, each slice starts when the one before it is finished.
.together {
--tablechart-animation-stagger: 1;
}
| Elstar | 42 |
|---|---|
| Jonagold | 28 |
| Braeburn | 18 |
| Gala | 12 |
<figure class="together" data-chart="donut">
<table>
<tbody>
<tr><th>Elstar</th><td>42</td></tr>
<tr><th>Jonagold</th><td>28</td></tr>
<tr><th>Braeburn</th><td>18</td></tr>
<tr><th>Gala</th><td>12</td></tr>
</tbody>
</table>
</figure>
If you want to draw the ring in one sweep instead, see Grow or sweep.
Grow or sweep
data-chart-animate on a figure sets how the chart builds:
| Value | What it does |
|---|---|
grow |
Each element grows from zero, one after the other. The default for columns, bars, waterfalls and donuts. A waterfall's columns come one after the other. |
sweep |
The chart is revealed in one movement. The default for lines and areas. A donut draws its ring in one sweep, and a waterfall builds at one speed. Columns and bars always grow. |
Lines
A line sweeps from left to right by default. With grow, it grows from zero as a whole, also below zero. The points move with the line, and the numbers appear when it is done.
| Jan | 12 |
|---|---|
| Feb | 18 |
| Mar | -6 |
| Apr | -11 |
| May | 4 |
| Jun | 15 |
<figure data-chart="line" data-chart-shape="smooth">
<figcaption><b>Sweep</b></figcaption>
<table>…</table>
</figure>
| Jan | 12 |
|---|---|
| Feb | 18 |
| Mar | -6 |
| Apr | -11 |
| May | 4 |
| Jun | 15 |
<figure data-chart="line" data-chart-shape="smooth" data-chart-animate="grow">
<figcaption><b>Grow</b></figcaption>
<table>…</table>
</figure>
Areas
An area works the same way. Stacked areas grow together.
| North | South | |
|---|---|---|
| 2020 | 42 | 18 |
| 2021 | 55 | 26 |
| 2022 | 38 | 31 |
| 2023 | 61 | 24 |
| 2024 | 49 | 35 |
<figure data-chart="area" data-chart-stack data-chart-shape="smooth" data-chart-legend>
<figcaption><b>Sweep</b></figcaption>
<table>…</table>
</figure>
| North | South | |
|---|---|---|
| 2020 | 42 | 18 |
| 2021 | 55 | 26 |
| 2022 | 38 | 31 |
| 2023 | 61 | 24 |
| 2024 | 49 | 35 |
<figure data-chart="area" data-chart-stack data-chart-shape="smooth" data-chart-animate="grow" data-chart-legend>
<figcaption><b>Grow</b></figcaption>
<table>…</table>
</figure>
Donuts
A donut grows slice by slice by default. With sweep, the ring is drawn in one movement at one speed, and the last slice slows to a stop. It takes as long as the slices would take one after the other.
| Elstar | 42 |
|---|---|
| Jonagold | 28 |
| Braeburn | 18 |
| Gala | 12 |
<figure data-chart="donut">
<figcaption><b>Grow</b></figcaption>
<table>…</table>
</figure>
| Elstar | 42 |
|---|---|
| Jonagold | 28 |
| Braeburn | 18 |
| Gala | 12 |
<figure data-chart="donut" data-chart-animate="sweep">
<figcaption><b>Sweep</b></figcaption>
<table>…</table>
</figure>
Waterfalls
A waterfall grows column by column by default, each column eased. With sweep, it builds at one speed: only the last one slows to a stop. The difference is small: in the Grow example every column has easing; in the Sweep example the columns grow at an even speed, and only the last one slows down. Both examples are slower than the default, so this is easier to see.
.slow-waterfall {
--tablechart-animation-element-duration: 1.5s;
}
| Picked | 74.5 |
|---|---|
| Windfalls | 28.2 |
| Bruised | -16.1 |
| Peelings | -13.3 |
| Pressed | 73.3 |
<figure class="slow-waterfall" data-chart="waterfall">
<figcaption><b>Grow</b></figcaption>
<table>…</table>
</figure>
| Picked | 74.5 |
|---|---|
| Windfalls | 28.2 |
| Bruised | -16.1 |
| Peelings | -13.3 |
| Pressed | 73.3 |
<figure class="slow-waterfall" data-chart="waterfall" data-chart-animate="sweep">
<figcaption><b>Sweep</b></figcaption>
<table>…</table>
</figure>
If you want to set it for every chart, use the animate option. Then data-chart-animate on a figure sets it for that one chart. A line or area with triggered steps (like from Reveal.js fragments) always sweeps.
init({ animate: "grow" });
No animation
If you want to show a chart without animation, add data-chart-animate="false" to the figure. The chart is then on the page from the start, also when it is not in view. If you want to do this for every chart, set the animate option to false. If the visitor prefers reduced motion, charts build without animation anyway.
<figure data-chart="column" data-chart-animate="false">
init({ animate: false });