1
我想在每行的末尾使用.append("svg:marker")
生成簡單的箭頭。我顯然做錯了事 - 非常感謝。在d3js中生成箭頭
var svg = d3.select("body") // select the 'body' element
.append("svg") // append an SVG element to the body
.attr("width", 600)
.attr("height", 600);
d3.csv("data/myarrows.csv", dottype1, function(error, lines) {
svg.append("g")
.selectAll("line")
.data(lines)
.enter()
.append("line")
.attr("x1", function(d) { return d.x1; })
.attr("y1", function(d) { return d.y1; })
.attr("x2", function(d) { return d.x2; })
.attr("y2", function(d) { return d.y2; })
.style("stroke", "brown") // colour the line
.style("stroke-width", 4) // adjust line width
.style("stroke-linecap", "square") // stroke-linecap type
svg.append("g")
.selectAll("marker")
.data(lines)
.enter()
.append("svg:marker")
.attr('viewBox', '0 -5 10 10')
.attr('refX', 6)
.attr('markerWidth', 10)
.attr('markerHeight', 10)
.attr('orient', 'auto')
.append('svg:line')
.attr('d', 'M0,-5L10,0L0,5')
;
});
function dottype1(d) {
d.x1 = +d.x1x1;
d.y1 = +d.y1y1;
d.x2 = +d.x2x2;
d.y2 = +d.y2y2;
return d;
}
<!DOCTYPE html>
<html>
<head>
<title>Arrows</title>
<meta charset="utf-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
</head>
<body>
<script type="text/javascript">
</script>
</body>
</html>