Skip to main content
100%

Stacked-to-Grouped Bars III

✓ Published0🌍 Public
TThanaporn-sk
Last edited Apr 22, 2017
Created on Mar 10, 2017

This interactive bar chart demonstrates a hybrid approach to visualizing stacked data, allowing users to switch between stacked, grouped, and percentage modes via radio buttons. In grouped mode, hovering over a layer highlights it and vertically re-aligns its bars so the baseline is zero, with the y-axis updating accordingly. The visualization uses D3 v4 with `d3.stack`, `d3.scaleBand`, and `d3.axisLeft`, rendering animated SVG rects with `transition` delays. It relies on synthetic data from a bump function and includes an automated initial transition cycling through the modes.

AI-generated description

Part III - Highlighted layers

One of the challenges with stacked bar charts is comparing values across bars, since the baseline is offset for all except the bottom layer. In this version, the entire layer is highlighed on mouseover, the bars adjust vertically to match up the layer baseline, and the y axis shifts to set the baseline to zero.

One remaining issue with this approach is that some bars may move above the top of the visualization. Any suggestions on how to deal with this best would be welcome!

Earlier versions:<br> Part I<br> Part II

Originally forked from <a href='http://bl.ocks.org/mbostock/'>mbostock</a>'s block: <a href='http://bl.ocks.org/mbostock/3943967'>Stacked-to-Grouped Bars</a>

Updated for D3 4.0

forked from <a href='http://bl.ocks.org/chornbaker/'>chornbaker</a>'s block: <a href='http://bl.ocks.org/chornbaker/98ade423c8e030ce3faea2fdced93e62'>Stacked-to-Grouped Bars III</a>

forked from <a href='http://bl.ocks.org/lorenzopub/'>lorenzopub</a>'s block: <a href='http://bl.ocks.org/lorenzopub/40c9bdc6bc3d25bf0ba4a14d84fe84bf'>Stacked-to-Grouped Bars III</a>

mit Licensed

Similar vizzes