2
我使用d3繪製圖表(我使用的是thix示例:https://gist.github.com/keiranlovett/8766741)。我需要添加一個鏈接。我添加文字,我試圖讓一個鏈接,但它不會顯示爲一個鏈接(我使用的是IE 11):使文本成爲svg中的鏈接
svg.append("g") //without doing this, impossible to put grid lines behind text
.attr({
xmlns: "http://www.w3.org/2000/svg",
xlink: "http://www.w3.org/1999/xlink",
width: 100,
height: 300
})
.attr({ "xlink:href": "#" })
.on("mouseover", function (d, i) {
//alert('aaa');
d3.select(this)
.attr({ "xlink:href": "http://example.com/" + "eeeeeeeeeeeeeeeeeee" });
})
.selectAll("text")
.data(tasks)
.enter()
.append("text")
.text(function (d) {
if (ammendmentsLinks.indexOf(d.contract) < 0) {
ammendmentsLinks = ammendmentsLinks + d.contract + ";";
return d.contract;
//return "";
}
else {
return "";
}
})
.attr("x", 20)
.attr("y", function (d, i) {
return i * 20;
})
.attr("font-size", 11)
.attr("text-anchor", "start")
.attr("text-height", 14)
.on("click", function (d) {
return click(d.contract);
});
我還添加了一些代碼行從http://jsfiddle.net/christopheviau/B9zcF/使文本鏈接,但它不工作。
如何讓我的文本鏈接?
您需要將''元素包裝在''元素中。 –
可否請你拿我的代碼並更新它?我對svg是新手,我沒有時間查看文檔,並且我需要完成一個任務來製作這張圖表,而且我很難讓它工作。謝謝 –
@RobertLongson確實,這工作(我不知道從jsfiddle元素是從HTML )。謝謝 –