【问题标题】:Change X and Y coordinate values on mouseover event in d3.js在 d3.js 中更改鼠标悬停事件的 X 和 Y 坐标值
【发布时间】:2015-07-31 18:38:50
【问题描述】:

我创建了鼠标悬停函数来显示我的折线图的 x 和 y 坐标。我想在鼠标悬停事件时显示正确的 x 和 y 坐标位置。有人可以帮我找出如何重写工具提示函数以显示正确的 x 和 y 坐标。谢谢。

var tooltip = d3.select("body")
     .data(data)
//    .enter()
    .append("div")
    .style("position", "absolute")
    .style("z-index", "10")
    .style("visibility", "hidden")
    .text(function(d){console.log((d.Mass+ ","+ d.Intensity));return (d.Mass+ ","+ d.Intensity);});

折线图的链接在以下位置。

http://jsbin.com/nipeko/edit?html,css,js,output

【问题讨论】:

标签: javascript jquery d3.js


【解决方案1】:

怎么样:

.on("mouseover", function(){
   var pos = d3.mouse(this);
   tooltip.text(xScale.invert(pos[0]).toFixed(1) + ' , ' + yScale.invert(pos[1]).toFixed(1));
   return tooltip.style("visibility", "visible");
 })

更新code

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-11
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多