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

Create a chord diagram from the data

To create a chord diagram from the matrix, we use the d3.chord() function. This function will convert our matrix to a set of SVG paths. Before we add the elements to the graph, we're first going to set up some d3.js helpers:

    var color = d3.scaleOrdinal()         .domain(d3.range(uniqueIds.length))         .range(d3.range(uniqueIds.length)             .map(function(i) { return d3.interpolateRainbow(i/uniqueIds.length);}));      var chord = d3.chord()         .padAngle(0.03);      var arc = d3.arc()         .innerRadius(innerRadius)         .outerRadius(outerRadius);      var ribbon = d3.ribbon()         .radius(innerRadius);

We set up a color d3.scaleOrdinal that creates a unique color for each of our unique IDs. Next, we create a d3.chord. With this function, we ...

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