I'm new to d3 and attempting to create a graph layout.
var w = 1000;
var h = 500;
var dataset = {
nodes: [{
name: 'Alice'
}, {
name: 'David'
}, {
name: 'Eve'
}],
edges: [{
source: 0,
target: 1
}, {
source: 1,
target: 2
}]
};
var svg = d3.select("body")
.append("svg")
.attr("height", h)
.attr("width", w);
var force = d3.layout.force()
.nodes(dataset.nodes)
.links(dataset.edges)
.size([w, h])
.linkDistance([50])
.start();
var nodes = svg.selectAll("circle")
.data(dataset.nodes)
.enter()
.append("circle")
.attr("r", 10)
.style("fill", "blue")
.call(force.drag);
var edges = svg.selectAll("line")
.data(dataset.edges)
.enter()
.append("line")
.style("stroke", "#999")
.style("stroke-width", 2);
You can view my fiddle here: http://jsfiddle.net/username/example/
I'm having trouble getting the graph to display correctly. Any advice or suggestions would be greatly appreciated.