Data Visualization Projects - Visualize Data with a Treemap Diagram

Tell us what’s happening:

the wii sports tile is not displayed, but does show up in the console.log(root.leaves())

Your code so far

const map = d3

.then(json => generateMap(json))
.catch(e => console.error(${}: ${e.message}));

const generateMap = (ds) => {

const categories ={ name }) => name);
const oScale = d3.scaleOrdinal(categories, colors);

const root = d3
.sum(d => d.value)
.sort((a, b) => b.height - a.height || b.value - a.value);

const cell = svg
.classed(‘tile’, true)
.attr(‘transform’, d => translate(${padding.left + d.x0},${ + d.y0}))
.attr(‘width’, d => d.x1 - d.x0)
.attr(‘height’, d => d.y1 - d.y0)
.attr(‘fill’, d => oScale(
.attr(‘data-name’, d =>
.attr(‘data-category’, d =>
.attr(‘data-value’, d =>

Your browser information:

full project:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36 OPR/

aha! the legend code (which I omitted from the post because I didn’t realize I had this problem in a previous project) was messing with the treemap code. I gave the legend it’s own

in the svg container
, and all is well!

hah, ‘<‘div’>’ creates a return line in posts

then, I realized the real problem was selectAll(‘g’). so I demoted the legend to a group again and added it back to the main container, and changed all selectAll statements in my code to select the class attributed below them and in stead of the type appended. Now, the code is truly scalable without changing the index file.

.classed(‘legend-item’, true)

instead of