I am trying to add text in force layout. First i am creating a svg group and i am appending circle and text into it. The circle is working fine but the text is not working. Here is the code
var node = svg.selectAll("g")
                    .data(measures.nodes)
                    .enter().append("g")
                    .attr("class", "node")
                    .call(node_drag);
var circle = node.append("circle")
                    .attr("fill", "blue")
                    .attr("r",5)
                    .attr("dx", ".10em")
                    .attr("dy", ".10em");
var text = node.append("text")
                .data(measures.nodes)
                .attr("color", "blue")
                .text(function(d){ return d.name; })
                The text is of the screen because you've missed out the positioning methods. If you add this you'll see text attached to the nodes.
        text.attr("x", function(d) { return d.x; })
        .attr("y", function(d) { return d.y; });
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With