Skip to main content
100%

Brushable Horizontal Bar Chart - I

✓ Published0🌍 Public
SSav10
Last edited Jul 27, 2016
Created on Jul 27, 2016

This example shows a brushable horizontal bar chart that lets viewers explore a large, randomly generated dataset by adjusting a selection box in a mini chart on the right. The main chart on the left displays the selected bars in detail, with the y-axis labels and bar lengths updating based on the brush extent. The chart uses D3 v3 with SVG rendering, employing `d3.svg.brush` for the interactive selection, `d3.scale.ordinal` and `d3.scale.linear` for scales, and an ordinal brush pattern adapted from an external example. Scrolling the mouse wheel also moves the brush, and resizing handles allow users to change the number of visible bars.

AI-generated description

This brushable horizontal bar chart gives you the option to browse through a large dataset without the separate bars becoming too small.

You have the option to adjust how many bars you're seeing at the same time by adjusting the size of the little box on the right mini chart.

You can also move the box and see the bars that you've selected appear in a bigger form on the left. Moving can be done either by grabbing and moving the box or scrolling

I have another version that uses a slightly different way to transition can be found here: Brushable Horizontal Bar Chart - II

The reason why the code is divided up into the overarching functions is to prepare it a bit already for the charting framework that I work with at my day job (and yes, I know the global variables are not-done, but I'm not known for writing beautiful or short code :) )

Why the rainbow? Just because it made it more fun to look at during the development :) (Please don't use a rainbow for a serious case though)

Some options to think about: You can update the x axis domain to update when you select a new set of bars, so that the largest bar always fills the space. This way you can see the smaller bars with more detail. Just wondering if that is confusing for a viewer... which I finally did in Brushable Horizontal Bar Chart - III

Although I found tidbits to get to this point all over the web, the initial help to set up an ordinal brush came from this example

Tested in (new versions of) Chrome, Firefox and Safari

Built with blockbuilder.org

forked from <a href='http://bl.ocks.org/nbremer/'>nbremer</a>'s block: <a href='http://bl.ocks.org/nbremer/d8dff2fa37345d54f9e58eb74db460d0'>Brushable Horizontal Bar Chart - I</a>

Similar vizzes