gpt4 book ai didi

javascript - 更新 d3 中的文本链接 URL

转载 作者:太空宇宙 更新时间:2023-11-04 16:29:35 26 4
gpt4 key购买 nike

我正在尝试在 d3 中的折线图的工具提示中实现链接。类似于 this .

链接将是数据的一个属性,因此我希望能够更改链接,因为工具提示侧重于数据的不同部分。

我没有使用 div,因为我想要一个响应式页面,并且不想使用绝对定位。

我不知道如何在设置后更改链接。到目前为止,我刚刚尝试调用:

  .attr("xlink:href", 'http://www.yahoo.com') 

第二次,但这不会更新它。

jsfiddle 的例子是 here .

感谢您的帮助。

最佳答案

您要将 href 添加到文本 DOM,而不是这样:

 d3.select('.tlink') //it will give you the text DOM
.attr("xlink:href", 'http://www.yahoo.com') //< link does not change?
.style('fill', 'red');

这样做:

 d3.select('a')//select anchor 
.attr("xlink:href", 'http://www.yahoo.com') //< link does not change?
.style('fill', 'red');

工作代码here

关于javascript - 更新 d3 中的文本链接 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39928013/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com