【发布时间】:2016-06-08 02:50:59
【问题描述】:
我正在关注this 示例,向我的圈子添加工具提示,显示在地图上。
var tooltip = d3.select("body")
.append("div")
.attr("id", "mytooltip")
.style("position", "absolute")
.style("z-index", "10")
.style("visibility", "hidden")
.text("a simple tooltip");
然后我得到了这个鼠标悬停
// callbackfunction preparing the data
// then
var feature = g.selectAll("circle")
.data(data.features)
.enter()
.append("circle")
//...
feature.on("mouseover",function(d) {
d3.select(this)
.transition()
.ease("elastic")
.duration(500)
.attr('r', function (d){
return (d.features.xy);
})
d3.select("#mytooltip")
.style("visibility", "visible")
.text(function(d) {
console.log(d.features.xy)
return (d.features.xy)
})
这不会显示xy 的值。
console.log 的输出是:
TypeError: undefined is not an object (evalating 'd.xy')
问题显然是使用d3.select("#mytooltip") 语句我输入了var tooltip,而我的data.features... 没有绑定到该var tooltip。如何将圆圈绑定到鼠标悬停(在调用 d3.select 后在 var feature = g.selectAll("circle") 中创建?
【问题讨论】:
标签: javascript d3.js mouseevent mouseover