O'Reilly logo

Expert Data Visualization by Jos Dirksen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading the country data

The first thing we have to do is load the data and convert it into a structure we can work with. In the previous example we used stratify(); in this example, we'll use a different way we can automatically have D3 do the conversion for us, called nest():

d3.text('./data/countries.csv', function(raw) {     var data = d3.dsvFormat(";").parse(raw)      // convert population and area to a number     data = data.map(function(el) {         el.Population = +el.Population;         el.Area = +el.Area;         el.Density = el.Population / el.Area;          if (el.Density === Infinity) el.Density = 0;             return el;     });      // group entries using nest and create hierarchy per continent     var entries = d3.nest()         .key(function (d) {return d.Continent; })  .entries(data); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required