繁体   English   中英

带有工具提示过渡问题的 D3 多线图

[英]D3 Multiline Chart with Tooltip Transition Issue

我一直在使用 d3 创建一个带有焦点和上下文刷亮的多折线图。 一切都很顺利,除了在过渡时,带有工具提示的数据点处的点移动到完全错误的位置。 我无法弄清楚是什么导致了这种情况。 任何帮助将非常感激。 我在这里附上了完整的代码,并在图表上注明了我很确定错误应该是:

http://jsbin.com/osumaq/20/edit

当按钮被点击时,一个新的 json 被传递给图表以进行读取。

我认为有问题的代码块是这样的:

topicEnter.append("g").selectAll(".dot")
        .data(function (d) { return d.values }).enter().append("circle").attr("clip-path", "url(#clip)")
        .attr("stroke", function (d) {
        return color(this.parentNode.__data__.name)
    })
        .attr("cx", function (d) {
        return x(d.date);
    })
        .attr("cy", function (d) {
        return y(d.probability);
    })
        .attr("r", 5)
        .attr("fill", "white").attr("fill-opacity", .5)
        .attr("stroke-width", 2).on("mouseover", function (d) {
        div.transition().duration(100).style("opacity", .9);
        div.html(this.parentNode.__data__.name + "<br/>" + d.probability).style("left", (d3.event.pageX) + "px").style("top", (d3.event.pageY - 28) + "px").attr('r', 8);
        d3.select(this).attr('r', 8)
    }).on("mouseout", function (d) {
        div.transition().duration(100).style("opacity", 0)
        d3.select(this).attr('r', 5);
    });

非常感谢你。

你说的工具提示是什么意思? 是当我们将鼠标悬停在点上时出现的窗口吗? 他们看起来很好。 我可以看到的是,当线条移动时,您的点没有移动,如果我不得不猜测,我会说您的输入和更新选择是混合的。 如果这些点已经在屏幕上并且你想更新它们的位置(通过调用你的方法update ),你应该有以下几行:

// Bind your data
topicEnter.append("g").selectAll(".dot")
    .data(function (d) { return d.values })
// Enter selection
topicEnter.enter().append("circle").attr("clip-path", "url(#clip)").attr("class", "dot");
// Update all the dots
topicEnter.attr("stroke", function (d) {
        return color(this.parentNode.__data__.name)
    })
    .attr("cx", function (d) {
        return x(d.date);
    })
    .attr("cy", function (d) {
        return y(d.probability);
    })
    [...]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM