All examples By author By category About

KatiRG

d3js clickable, sortable stacked bar chart

Stacked bar chart with a clickable legend to display one class of bars at a time, with the option of sorting them afterwards.

Builds on my clickable stacked bar chart, which was based on Mike Bostock's stacked bar chart and yuuniverse4444’s block #8325617, and integrates Mike Bostock's sortable bar chart.

Note: my version fixes a small inaccuracy in Mike Bostock's original code in which the heights and y-position of the bars are not calculated directly from the data value, but on the difference between the cumulative values in the stacked bar. This inaccuracy, which is usually only around 1 pixel, is not noticeable until a single category is sorted and you can see all the bars side by side in decreasing order.

My fix is a crude hack but it works!