Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Question is quite dated, but since I don't see an answer and someone might face the same problem, here it is.</p> <p>The reason why simple replacement of <em>diagonal</em> with <em>line</em> is not working is because <em>d3.svg.line</em> and <em>d3.svg.diagonal</em> return different results:</p> <ul> <li><em>d3.svg.diagonal</em> returns function that accepts datum and its index and transforms it to path using <em>projection</em>. In other words <em>diagonal.projection</em> determines how the function will get points' coordinates from supplied datum.</li> <li><em>d3.svg.line</em> returns function that accepts an array of points of the line and transforms it to path. Methods <em>line.x</em> and <em>line.y</em> determine how coordinates of the point retreived from the single element of supplied array</li> </ul> <p><a href="https://github.com/mbostock/d3/wiki/SVG-Shapes" rel="noreferrer">D3 SVG-Shapes reference</a></p> <p><a href="https://www.dashingd3js.com/svg-paths-and-d3js" rel="noreferrer">SVG Paths and D3.js</a></p> <p>So you can not use result of the <em>d3.svg.line</em> directly in d3 selections (at least when you want to draw multiple lines). </p> <p>You need to wrap it in another function like this:</p> <pre><code>var line = d3.svg.line() .x( function(point) { return point.lx; }) .y( function(point) { return point.ly; }); function lineData(d){ // i'm assuming here that supplied datum // is a link between 'source' and 'target' var points = [ {lx: d.source.x, ly: d.source.y}, {lx: d.target.x, ly: d.target.y} ]; return line(points); } // usage: var link= svg.selectAll("path") .data(links) .enter().append("path") .attr("d",lineData) .attr("class", ".link") .attr("stroke", "black") .attr("stroke-width", "2px") .attr("shape-rendering", "auto") .attr("fill", "none"); </code></pre> <p>Here's working version of jsFiddle <em>mobeets</em> posted: <a href="http://jsfiddle.net/8xrU7/" rel="noreferrer">jsFiddle</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload