我正在尝试添加一个显示区域名称的工具提示,当您将鼠标悬停在d3.js中的地图上时.输入是一个topojson文件,我已经能够成功生成带有区域边界的地图,并突出显示当前选定的区域.
对于提示我试图做类似的东西这个,但没有任何反应都没有.我用过的代码如下.工具提示代码即将结束.
var width = 960,
height = 600;
var projection = d3.geo.albers()
.center([87, 28])
.rotate([-85, 0])
.parallels([27, 32]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.append("rect")
.attr("width", width)
.attr("height", height);
var g = svg.append("g");
var div = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 1e-6);
d3.json("data/nepal3.json", function(error, npl) {
var districts = topojson.feature(npl, npl.objects.nepal_districts);
projection
.scale(1)
.translate([0, 0]);
var b = path.bounds(districts),
s = .95 / Math.max((b[1][0] - b[0][0]) / width, (b[1][1] - b[0][1]) …Run Code Online (Sandbox Code Playgroud)