Adds a new point to a subpath and connects that point to the last point in the subpath by using a straight line.
![]() |
Syntax
var retval = CanvasRenderingContext2D.lineTo(x, y);Parameters
- x [in]
-
Type: Floating-point
The x-coordinate, in pixels.
- y [in]
-
Type: Floating-point
The y-coordinate, in pixels.
Return value
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Standards information
- HTML Canvas 2D Context, Section 9
Examples
The following code example uses the moveTo and lineTo methods to incrementally draw horizontal lines across the canvas.
<html>
<head>
<title>Lineto example</title>
<script type="text/javascript">
function draw() {
var canvas = document.getElementById("MyCanvas");
if (canvas.getContext) {
var ctx = canvas.getContext("2d");
for (i = 10; i < 500; i += 20) {
ctx.moveTo(0, i);
ctx.lineTo(canvas.width, i);
ctx.stroke();
}
}
}
</script>
</head>
<body onload="draw()">
<canvas id="MyCanvas" width="600" height="600">This browser or document mode doesn't support canvas</canvas>
</body>
</html>
See also
Send comments about this topic to Microsoft
Build date: 11/28/2012
.png)
.png)