Skip to main content
100%

Stacked Bar Update Pattern

✓ Published0🌍 Public
FFrissAnalytics
Last edited Sep 25, 2018
Created on Sep 25, 2018

This example demonstrates the D3 general update pattern for smoothly animating changes in a stacked bar chart as new random data arrives every second. Seven individuals are displayed along the x-axis, with colored segments representing six categorical values, while the y-axis scale adjusts to accommodate the new total sum for each person. The code uses `d3.stack` with `d3.stackOrderNone`, a ColorBrewer qualitative palette, and `d3.scaleBand` paired with `d3.scaleLinear`. Transitions are driven by D3’s `transition()` method, with data generated via the jeezy library and helper functions from `d3-marcon` for layout.

AI-generated description

Use D3's general update pattern to animate stacked bar chart transitions.

Data shown here is in this format:

<table> <thead> <tr> <th>name</th> <th>a</th> <th>b</th> <th>c</th> <th>d</th> <th>e</th> <th>f</th> <th>sum</th> </tr> </thead> <tbody> <tr> <td>Ann</td> <td>8</td> <td>6</td> <td>3</td> <td>6</td> <td>1</td> <td>1</td> <td>25</td> </tr> <tr> <td>Bob</td> <td>1</td> <td>9</td> <td>10</td> <td>1</td> <td>5</td> <td>8</td> <td>34</td> </tr> <tr> <td>Jean</td> <td>3</td> <td>4</td> <td>3</td> <td>2</td> <td>1</td> <td>8</td> <td>21</td> </tr> <tr> <td>Chuck</td> <td>2</td> <td>3</td> <td>5</td> <td>8</td> <td>5</td> <td>9</td> <td>32</td> </tr> <tr> <td>Denise</td> <td>9</td> <td>10</td> <td>3</td> <td>8</td> <td>8</td> <td>8</td> <td>46</td> </tr> <tr> <td>Eric</td> <td>3</td> <td>9</td> <td>2</td> <td>4</td> <td>10</td> <td>4</td> <td>32</td> </tr> <tr> <td>Frida</td> <td>6</td> <td>6</td> <td>3</td> <td>7</td> <td>10</td> <td>6</td> <td>38</td> </tr> </tbody> </table>

Axis styling from this block. Colors from ColorBrewer.

forked from <a href='http://bl.ocks.org/HarryStevens/'>HarryStevens</a>'s block: <a href='http://bl.ocks.org/HarryStevens/7e3ec1a6722a153a5d102b6c42f4501d'>Stacked Bar Update Pattern</a>

gpl-3.0 Licensed

Similar vizzes