📜 ⬆️ ⬇️

We draw graphics through ... javascript

Information is generally well known, but it may be useful for newcomers (like me).

There was a recent need to draw the charts javascript. As a result, the canvas element from WHATWG and its specification were found . Thing is extremely attractive. Allows you to draw here such things:

It is done like this:
<html>
<head>
<script type = "application / x-javascript">
function draw () {
var canvas = document.getElementById ("canvas");
var ctx = canvas.getContext ("2d");

ctx.fillStyle = "rgb (200,0,0)";
ctx.fillRect (10, 10, 55, 50);
')
ctx.fillStyle = "rgba (0, 0, 200, 0.5)";
ctx.fillRect (30, 30, 55, 50);
}
</ script>
</ head>
<body onload = "draw ()">
<canvas id = "canvas" width = "300" height = "300"> </ canvas>
</ body>
</ html>

The example is taken from the description on Mozilla Developer Center .
Somewhat sad that native support for this element is only in Opera 9, Firefox 1.5 and Safari 2. And IE and the 6th, and 7th as usual ahead of the rest.
The situation is already saved by the already written emulation layers of this element for IE via VML .

Source: https://habr.com/ru/post/19726/


All Articles