From the course: D3.js Essential Training

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Manipulating data with. group() and .rollup()

Manipulating data with. group() and .rollup() - D3.js Tutorial

From the course: D3.js Essential Training

Manipulating data with. group() and .rollup()

- [Instructor] Being great with D3 means being great with data, and there are a lot of D3 functions to help you in this objective. Of course, you can also use vanilla JavaScript on your data, but D3 makes some things a lot easier. In this video, we're going to learn how to nest flat data using group and rollup, a much faster and cleaner alternative to reorganizing your files or writing custom code in JavaScript. In the exercise file, I have provided a function to generate some data and that's going to generate flat data. So, let's start just by looking at what that provides us. It's given us this array of length 120, and each item in the array has a Date object, a Month, and a Value. So, the data types are already correct and it's ready for us to use. So, let's start by grouping by Month. So, we can say const groupedData is d3.group, and then we pass in the data we want which is generatedData. And we say for each object, I want you to group by Month. And then, let's see what we get…

Contents