2015-06-08 75 views
2

我使用http://bl.ocks.org/d3noob/5141278示例創建了一個有向圖。我已經附加了標記的路徑:不顯示d3標記

var svg = d3.select("#entitiesGraph").append("svg") 
.attr("width", width) 
.attr("height", height); 

svg.append("svg:defs").selectAll("marker") 
.data(["end"]) 
.enter().append("svg:marker") 
.attr("id", "end") 
.attr("viewBox", "0 -5 10 10") 
.attr("refX", 15) 
.attr("refY", -1.5) 
.attr("markerWidth", 12) 
.attr("markerHeight", 12) 
.attr("orient", "auto") 
.append("svg:path") 
.attr("d", "M0,-5L10,0L0,5"); 

var path = svg.append("svg:g").selectAll("path") 
.data(force.links()) 
.enter().append("svg:path") 
.attr("marker-end", "url(#end)"); 

,一切工作正常,除了標誌 - 他們不顯示,但是在JavaScript控制檯我可以看到,他們被附加到SVG容器。

有人想法可能是什麼問題?

+1

你爲什麼認爲他們沒有顯示? http://jsfiddle.net/3ydk4Lwy/ – user3714582

+0

我試過你的例子,它工作。然而不是在我的代碼中,這很奇怪。我正在創建的圖形可視化是一個更大的項目的一部分,我們正在使用許多庫,恐怕可能會有一些依賴衝突。但我不知道如何找到它... – Rita

+0

你的應用程序中的節點圈的大小是多少? – VividD

回答

0

不確定您現在是否已經解決了此挑戰。我面臨類似的問題。我在你的問題的情況下的做法是:

var svg = d3.select("#entitiesGraph").append("svg") 
.attr("width", width) 
.attr("height", height); 

svg.append("svg:defs").selectAll("marker") 
.data(["end"]) 
.enter().append("svg:marker") 
.attr("id", window.location.href + "/end") // not .attr("id", "end") 
.attr("viewBox", "0 -5 10 10") 
.attr("refX", 15) 
.attr("refY", -1.5) 
.attr("markerWidth", 12) 
.attr("markerHeight", 12) 
.attr("orient", "auto") 
.append("svg:path") 
.attr("d", "M0,-5L10,0L0,5"); 

var path = svg.append("svg:g").selectAll("path") 
.data(force.links()) 
.enter().append("svg:path") 
.attr("marker-end", "url(#" + window.location.href + "/end)"); // not .attr("marker-end", "url(#end)"); 

認爲這是因爲你的代碼是尋找具有「www.yourdomain /」下的「結束」的ID,而你希望它看起來之下元素「www.yourdomain/partofyourwebsite/pageGraphIsRenderedIn」雖然我不確定這是否正確。

+0

嗨,是的,這個問題真的是由於一個錯誤的網址;) – Rita