Explanation on how to draw a straight line in Raphael.js

12,313

It's very simple:

var line = paper.path( "M100,0 L30,100" );

You can also build your paths out of arrays, which is really useful in some circumstances.

var line = paper.path( ["M", 100, 0, "L", 30, 100 ] );
Share:
12,313
Wesley Skeen
Author by

Wesley Skeen

Updated on June 04, 2022

Comments

  • Wesley Skeen
    Wesley Skeen almost 2 years

    I would like some help on the path constructor in Raphael. Im not sure how to draw a straight line from one point to another. I have

    var line = paper.path(M 100 0 1 0 30 100)
    

    I want to draw a line from point1 (100 0) to point2 (30 100)

  • Kevin Nielsen
    Kevin Nielsen over 11 years
    M = "move to" and L = "line to". Path syntax is entirely directive based. If you want the complete list of commands, check out the w3c spec at w3.org/TR/SVG/paths.html.
  • Kevin Nielsen
    Kevin Nielsen over 11 years
    It's also worth noting that you can use relative versions of virtually every directive -- so "M100,0 L30,100" and "M100,0 l-70,100" will produce the same output.