我正在使用d3将地球仪放到网页上。我能够为地球上的每条路径附加一个标题(路径=国家多边形)。但我无法将标题作为该国的名称。
var svg = d3.select("#canvas"),
globe = svg.selectAll(".country"),
sens = .25, //sensitivity
circle,
zoomed = false;
width = window.innerWidth;
height = window.innerHeight;
svg
.attr("width", width)
.attr("height", height)
var projection = d3.geo.orthographic()
.scale(300)
.translate([width / 2, height /2 ])
.rotate([0,0])
.clipAngle(90)
.precision(.1);
var path = d3.geo.path()
.projection(projection);
d3.json("world.json", function(error, world) {
circle = svg.append("circle")
.attr('cx', width / 2)
.attr('cy', height / 2)
.attr('r', projection.scale())
.attr("stroke", "#aaaaaa")
.attr("stroke-width", "1")
.attr("fill", "white");
countries = topojson.feature(world, world.objects.countries).features;
globe = globe.data(countries)
.enter()
.append("path")
.attr("d", path)
.attr("class", "country")
.attr("id", function(d){return d.properties.id})
.on("dblclick", zoomIn)
.on("click", panTo)
.append('title').text('This is a line.');
所以我可以为标题添加一个字符串,但是如何输入国家名称?
.append('title').text(function(d){return d.properties.id});
抛出错误:
“Uncaught TypeError:无法调用方法'createDocumentFragment' 空“