We are ready to port the bar chart from last time to use d3v4 This will give us access to the latest innovations available to us in the d3 library.
x
scale.x
axis.<style>
section.Notice that we’ve switched from nest.entries()
to nest.map.entries()
.
Let’s break it down:
d3.nest()
.key(function(d) { return d.CAUSE; })
.rollup(function(leaves) { return leaves.length; })
.map(data)
Instead of an array of key/value pairs, this gives us a d3.map()
object, where each key is the CAUSE and its value is the number of deaths. Something like:
{$ABDOMINAL PAINS: 28, $ACCIDENT: 45, $ASTHMA: 23, $BOILS: 3, ....}
with extra properties
Now that we are using the latest version of d3, we can take advantage of the years of accummulated knowledge and experience that went into the new version. All the documentation and most of the new examples use d3v4 as their context, which means it will be more and more relevant to improving our chart.
If you’re like me, you might remember that each row in the datset represents information, like this:
{{CAUSE:"FEVER/MALARIA", AGE:"38", OTHER:"", SEX:"1"}}
.
Let’s explore the dataset more deeply. Next, we’ll visualize deaths by cause by gender.