【发布时间】:2017-07-31 08:53:17
【问题描述】:
我正在尝试在SVG 圆圈内附加文本,例如我的D3 地图中的 this 示例。我在 SO 上看到了很多类似的问题 - 我用它们编写了下面的代码,但不明白为什么它根本没有出现。
d3.json("https://raw.githubusercontent.com/d3/d3.github.com/master/world-110m.v1.json", function (error, topo) {
if (error) throw error;
gBackground.append("g")
.attr("id", "country")
.selectAll("path")
.data(topojson.feature(topo, topo.objects.countries).features)
.enter().append("path")
.attr("d", path);
gBackground.append("path")
.datum(topojson.mesh(topo, topo.objects.countries, function (a, b) { return a !== b; }))
.attr("id", "country-borders")
.attr("d", path);
console.log("Background Drawn");
var point = gPoints.selectAll("circle")
.data(pointsData)
.enter()
.append("circle")
.attr("cx", function (d) { return d.location[0]; })
.attr("cy", function (d) { return d.location[1]; })
.attr("r", 10)
//Other attributes and mouseovers, etc
var texts = gPoints.selectAll("text")
.data(pointsData)
.enter()
.append("text")
.text(function (d) { return d.performance; });
console.log("Points Drawn");
});
【问题讨论】:
标签: javascript d3.js svg text