Here is an example showing some text in circles with data from a json file: http://bl.ocks.org/4474971 . Which gives the following:

The main idea is to encapsulate the text and the circle in the same “ div ” as in html, so that the logo and company name match the same div in the page title,
Main code:
var width = 960, height = 500; var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height) d3.json("data.json", function(json) { var elem = svg.selectAll("g") .data(json.nodes) var elemEnter = elem.enter() .append("g") .attr("transform", function(d){return "translate("+d.x+",80)"}) var circle = elemEnter.append("circle") .attr("r", function(d){return dr} ) .attr("stroke","black") .attr("fill", "white") elemEnter.append("text") .attr("dx", function(d){return -20}) .text(function(d){return d.label}) })
and json file:
{"nodes":[ {"x":80, "r":40, "label":"Node 1"}, {"x":200, "r":60, "label":"Node 2"}, {"x":380, "r":80, "label":"Node 3"} ]}
The resulting html code shows the required encapsulation:
<svg width="960" height="500"> <g transform="translate(80,80)"> <circle r="40" stroke="black" fill="white"></circle> <text dx="-20">Node 1</text> </g> <g transform="translate(200,80)"> <circle r="60" stroke="black" fill="white"></circle> <text dx="-20">Node 2</text> </g> <g transform="translate(380,80)"> <circle r="80" stroke="black" fill="white"></circle> <text dx="-20">Node 3</text> </g> </svg>
Christopher Chiche Nov 29 '12 at 13:37 2012-11-29 13:37
source share