Skip to main content
100%

Exploring survey data interactively - both axes

✓ Published0🌍 Public
MMarc
Last edited Nov 21, 2019
Created on Nov 21, 2019

This interactive bar chart lets users explore survey data by selecting a variable from a dropdown menu. Changing the selection updates both the y-axis and the heights of the bars, which display averages for variables like stress, health, and family size grouped by a fixed x-axis. The visualization uses D3 v5’s general update pattern with `d3.nest()` and `d3.rollup` to aggregate the dataset, which is loaded as JSON. Code defines scales, axes, and bar rendering with SVG, while the dropdown options are generated through a data join.

AI-generated description

Dynamic axes using the update pattern example

In this visualization, the data that's rendered in the view changes because of user interaction

Steps

  • Make the nesting dynamic
  • Nest on health, stress dynamically
  • Make x-axis interactive so remove and enter are also needed

Concept

A chart showing distribution or relation between to variables. The vriables can be chosen through a dropdown menu resulting in a rerendering of datapoints and axis.

  • Group students by a variable on the x axis.
  • Get data from different vars on y axis

Notes

  • Note that d3 has a new way of handling enter, update and exit explicitly as explained in this article.
  • The options in the form are generated from the data using a data join
  • The scales, the data and the selected opton are global. I found that to be nicer than to keep passing them everywhere
  • If you want to add a new option to this interactive graph, all you have to do is add a new computed variable in the prepareData module and everything else will happen automatic
  • Observe how prepareData module now exports 2 functions separately which we can use to have greater control over the transformation of data from our index.js file.

Inspiration

MIT Licensed

Similar vizzes