Graph visualization with D3.js
D3.js
provides us with the d3.layout.force()
function that use the Force Atlas layout algorithm and help us to visualize our graph. Refer to Chapter 3, Data Visualization, for instructions on how to create D3.js
visualizations.
Firstly, we need to define the CSS style for the nodes, links, and node labels.
<style> .link { fill: none; stroke: #666; stroke-width: 1.5px; } .node circle { fill: steelblue; stroke: #fff; stroke-width: 1.5px; } .node text { pointer-events: none; font: 10px sans-serif; } </style>
Then, we need to refer the
d3js
library.<script src="http://d3js.org/d3.v3.min.js"></script>
Then, we need to define the
width
andheight
parameters for thesvg
container and include into thebody
tag.var width = 1100, height = 800 var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height);
Now, we define the properties of the
force
layout such asgravity
,distance
, andsize
.var...