1 var width = 600; 2 var height = 400; 3
4 var svg = d3.select("#body") 5 .append("svg") 6 .attr("width",width) 7 .attr("height",height) 8
9 var dataList = { 10 source: { x: 100, y: 100 }, 11 target: { x: 300, y: 200 } 12 }
1 //建立一個對角線生成器
2 var diagonal = d3.svg.diagonal() 3
4
5 //添加路徑
6 svg.append("path") 7 .attr("d",diagonal(dataList)) 8 .attr("fill","none") 9 .attr("stroke","black") 10 .attr("stroke-width","3px")
1 //使用投影函數
2 var diagonal = d3.svg.diagonal() 3 .projection(function(d){ 4 var x = d.x * 1.5
5 var y = d.y * 1.5
6 return [x,y] 7 })