SVG Line element

24 views
Skip to first unread message

ice

unread,
Apr 18, 2014, 9:51:30 AM4/18/14
to d3...@googlegroups.com
Hi, 

I was wondering is svg line element not the same as rect element or any other element? I have been trying to make this work (code shown below) but it doesn't seem to? Can anyone identify the problem and give a explanation of how its different to other svg elements? Like why is it not possible to give line elements a class and create lines at different times when a function is called? Why is path appended when line element is used?   
   d3.svg.append("line")
        .attr("x1", x1)
        .attr("y1", y1)
        .attr("x2", x2)
        .attr("y2", y2)
        .style("stroke", colour);

Any help will be really appreciated! I can't seem to find a good explanation, sorry if I missed something out. 

Thank you! 

Scott Murray

unread,
Apr 18, 2014, 10:36:35 AM4/18/14
to d3...@googlegroups.com
You can definitely assign lines classes, just like other elements:

http://alignedleft.com/tutorials/d3/an-svg-primer

It's hard to know what's going on without seeing the rest of your code, but one question:  Where are you appending the line?  Normally you begin with a select statement, like:

d3.select("svg").append("line")
.attr("x1", x1)


…or store a reference to a selection, and start with that:

var svg = d3.select("svg");

svg.append("line")
.attr("x1", x1)

Either way, d3.svg.append("line") doesn't really make sense.  I think you may be conflating selection.append() and d3.svg.line, which creates a line generator function, see:


Scott



--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages