Accepted answer

With .append("g") you insert a SVG Group Element.

The problem is, that you try to apply attributes that are for circles, like the radius with .attr("r",15), to the group element.

You have to use circles if you want to draw a circle. Group elements do not have any shape. They are used to group elements like circles.

A solution would be to append the g element and transform it to the location of the node. I updated your code in the following snippet. I used the group elements and added the circle, image and text inside the group elements.

Moreover I removed the backslashes before each angular bracket and set the title to the field name instead of label.

var width = 960,
    height = 500;

var color = d3.scale.category20();

var force = d3.layout.force()
    .size([width, height]);

var svg ="body").append("svg")
    .attr("width", width)
    .attr("height", height);

var graph = getData();

var nodeMap = {};

graph.nodes.forEach(function(d) { nodeMap[] = d; });

graph.links.forEach(function(l) {
    l.source = nodeMap[l.source]; = nodeMap[];


var link = svg.selectAll(".link")
    .attr("class", "link")
    .style("stroke", function(d) {
        return d.line_color;
    .style("stroke-width", function(d) {
        return Math.sqrt(d.value)+1;

var node = svg.selectAll(".node")
    .attr("transform", function(d){return "translate("+d.x+","+d.y+")"})

    .attr("class", "node")
    .attr("r", 15)
    .style("fill", function(d) { return d.fill_color; })
    .on("click", function(d){
      alert("You clicked on node " +;

    .text(function(d) { return; });

    .attr("xlink:href", function(d) { return d.image_url })
    .attr("x", -8)
    .attr("y", -8)
    .attr("width", 26)
    .attr("height", 26);

    .attr("dx", function(d) { 
        if (d.image_url == "/profile.png"){
          return 100;
          return 16;
    .attr("dy", function(d) { 
        if (d.image_url == "/profile.png"){
          return 100;
          return ".35em";
    // .attr("dy", ".35em")
    .text(function(d) { return });

force.on("tick", function() {
    link.attr("x1", function(d) { return d.source.x; })
        .attr("y1", function(d) { return d.source.y; })
        .attr("x2", function(d) { return; })
        .attr("y2", function(d) { return; });

    node.attr("transform", function(d){return "translate("+d.x+","+d.y+")"});

function getData() {
  return {
<script src=""></script>

Related Query

More Query from same tag