Javascript 线';点x1、x2、y1、y2与径向树中的节点不重合

Javascript 线';点x1、x2、y1、y2与径向树中的节点不重合,javascript,svg,d3.js,Javascript,Svg,D3.js,我尝试在径向图中用svg线连接节点,但点x1、x2、y1、y2与节点不重合。我把极坐标换成笛卡尔坐标,但我想我遗漏了什么 这是我的答案。到目前为止,我试图解决这个问题 请帮忙!谢谢 line.append("line") .attr("class", "line") .attr("x1", function(d) {return d.source.y * Math.cos(d.source.x-90);}) .attr("y1", function(d) {r

我尝试在径向图中用svg线连接节点,但点x1、x2、y1、y2与节点不重合。我把极坐标换成笛卡尔坐标,但我想我遗漏了什么

这是我的答案。到目前为止,我试图解决这个问题

请帮忙!谢谢

line.append("line")
      .attr("class", "line")
      .attr("x1", function(d) {return d.source.y * Math.cos(d.source.x-90);})
      .attr("y1", function(d) {return d.source.y * Math.sin(d.source.x-90);})
      .attr("x2", function(d) {return d.target.y * Math.cos(d.target.x-90);})
      .attr("y2", function(d) {return d.target.y * Math.sin(d.target.x-90);})  
      .attr("stroke-width", 3)
      .attr("stroke", "steelblue");

你太近了!Javascript三角函数以弧度而不是度数工作,因此如果您考虑到这一点,您的图形将工作

line.append("line")
  .attr("class", "line")
  .attr("x1", function(d) {return d.source.y * Math.cos(Math.PI/180 * (d.source.x-90));})
  .attr("y1", function(d) {return d.source.y * Math.sin(Math.PI/180 * (d.source.x-90));})
  .attr("x2", function(d) {return d.target.y * Math.cos(Math.PI/180 * (d.target.x-90));})
  .attr("y2", function(d) {return d.target.y * Math.sin(Math.PI/180 * (d.target.x-90));})  
  .attr("stroke-width", 3)
  .attr("stroke", "steelblue");

你太近了!Javascript三角函数以弧度而不是度数工作,因此如果您考虑到这一点,您的图形将工作

line.append("line")
  .attr("class", "line")
  .attr("x1", function(d) {return d.source.y * Math.cos(Math.PI/180 * (d.source.x-90));})
  .attr("y1", function(d) {return d.source.y * Math.sin(Math.PI/180 * (d.source.x-90));})
  .attr("x2", function(d) {return d.target.y * Math.cos(Math.PI/180 * (d.target.x-90));})
  .attr("y2", function(d) {return d.target.y * Math.sin(Math.PI/180 * (d.target.x-90));})  
  .attr("stroke-width", 3)
  .attr("stroke", "steelblue");

辉煌!非常感谢:)真棒!非常感谢:)