Elements: Line, Polyline, Polygon, and Path

Learn the basics of the line, polyline, polygon, and path elements in D3.

We'll cover the following

Line

A line is a simple line between two points and is described by four required attributes.

  • x1: The x position of the first end of the line as measured from the left of the screen
  • y1: The y position of the first end of the line as measured from the top of the screen
  • x2: The x position of the second end of the line as measured from the left of the screen
  • y2: The y position of the second end of the line as measured from the top of the screen

The following is an example of the code section required to draw a line. A notable addition to this code is the style declaration. In this case, the line does not have color, and this can be added with the stroke style, which applies color to a line:

Get hands-on with 1200+ tech skills courses.