Skip to main content
100%

Barchart as an input device

✓ Published0🌍 Public
AAlainRo
Last edited Mar 4, 2018
Created on Mar 4, 2018

Two linked barcharts display the same dataset of eight numeric values, one horizontal and one vertical. Each bar is implemented as a d3.brushX or d3.brushY selection rectangle, so dragging a bar changes its value. A shared refresh function updates both charts simultaneously, showing the current value labels. This turns the familiar bar chart into a direct manipulation input device for editing data.

AI-generated description

Barchart as an input device

Brushes can be used to draw a barchart. This gives an easy way to input or adjust values with the mouse !!!

The d3 brush is a complex piece of logic taking care of events and user feed-backs. Among other characterics it exposes a nice selection rectangle which can be used as a bar !!!

2D-brushes come in two flavors see official API v4 doc

  • d3.brushX()
  • d3.brushY()

Let's try both of them on this example.

Code comments

Code is made of:

  • CSS
  • a data definition in the form of: [{index:2, value: 23.34}, ...]
  • two almost identical barchart generators (horizontal/vertical) allowing to drag a bar to a new value
  • a refresh function which propagates data updates into the two barcharts

Enjoy !!

forked from <a href='http://bl.ocks.org/AlainRo/'>AlainRo</a>'s block: <a href='http://bl.ocks.org/AlainRo/9264cd08e341f2c92f020c39642c34d1'>BarChart with draggable bars to input/adjust data values (Horizontal + Vertical)</a>

mit Licensed

Similar vizzes