From the course: D3.js Essential Training for Data Scientists

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Make flat data multidimensional

Make flat data multidimensional - D3.js Tutorial

From the course: D3.js Essential Training for Data Scientists

Start my 1-month free trial

Make flat data multidimensional

- [Instructor] D3 has a number of functions for manipulating data. We've already seen map which runs a transformation on each row of a data set. Now we're going to look at nest. Nest turns flat tabular data into hierarchical data. Change the reference in d3.html to dataHandlers and reopen that file and find the section that's got the C-S-V data handler which for me is at the top. If we just log this data to the console, let's see what we actually start with by way of data. And we see that we have an array of objects. We've got one object for each row. Each object contains a month which is a date and price. So go back to atom and declare a new variable called nested data. And we set it to d3.nest and we give it two parameters: .key and .entries which you can style any way you like. I'm going to style mine like that. Entries is the array containing the data we want to nest and in our case that's called data because that's the name we've given it here in these brackets, so we just type…

Contents