How to make a radial line segment using D3.js

I would like to create a line using polar coordinates.

Example: A line whose center is at cx = 0, cy = 0, at an angle pi / 4, but only from the radius of the beginning 4 and the radius of the end 7.

I could use the math and do this work myself, but d3.js seems to have a radial line generator , but I find the documentation hard to understand, being d3 noob.

+4
source share
1 answer

Using a linear generator is relatively simple. You can use it with default parameters and specify everything in such data:

d3.svg.line.radial()([[4,Math.PI/4],[7,Math.PI/4]]); 

As an alternative, you can only provide data that changes, and everything else is by default:

  var line = d3.svg.line.radial() .angle(Math.PI/4) .radius(function(d) { return d; }); line([4,7]); 
+5
source

Source: https://habr.com/ru/post/1499371/


All Articles