Lines
A line path in jCanvas is, essentially, one or more contiguous line segments.
Basic Usage
You can draw a line path using the drawLine()
method. Coordinates are defined using x1
, y1
, x2
, y2
, and so on (as many as necessary).
Closing a line path
You can, optionally, close a line path, which will connect its start and end points with an extra line. To do so, use the closed
property.
Rounded Corners
You can round the corners of a line path using the rounded
property.
Plotting an array of points
If you wish to utilize an array containing your points, you can easily construct the drawLine()
object using a loop.
Dashed lines
Browsers began recently adopting the ability to create dashed lines. To do so in jCanvas, specify the strokeDash
and strokeDashOffset
properties.
The strokeDash
property accepts an array of one or two numbers, and the strokeDashOffset
property accepts a single number. See the Properties page for specific usage details.
Vectors
Instead of the drawLine()
method, you can also plot line segments using the [drawVector()](/jcanvas/docs/vectors/)
method (which draws lines using vectors rather than (x, y) coordinates).