In the documentation for d3.js I cannot find a straightforward way to draw a simple line segment between two points. The only way I can find there to do this is one that requires creating callbacks for x and y, etc., etc. I.e. a major production just to draw a simple line segment.
Is there something simpler?
The line generator is then used to make a line. Syntax: d3. line();
Step 1: Draw a line of any length. Step 2: Mark the starting point of the line segment. Step 3: Take a ruler and place the pointer of the compass, apart from the pencil's lead. Step 4: Place the pointer of the compass at the starting point and mark an arc on the line with the pencil point.
You use the x and y scale functions. svg. append("line") .
Simplest is:
d3.select('svg')
.append('path')
.attr({
d: "M0,0L200,200"
stroke: '#000'
});
This is not too bad:
var simpleLine = d3.svg.line()
d3.select('svg')
.append('path')
.attr({
d: simpleLine([[0,0],[200,200]]),
stroke: '#000'
});
Still....
I don't know if this is more simple, but it is maybe more direct:
d3.select('svg')
.append('line')
.attr({
x1: 0,
y1: 0,
x2: 200,
y2: 200,
stroke: '#000'
})
(All three examples draw a line from 0,0 to 200,200)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With