Share RGraph on Facebook Share RGraph on Twitter

HTML5 canvas reference - learn how to use the canvas tag!

Learn how to use the canvas tag API

Learn how to use HTML5 canvas! With the new HTML5 specification comes a whole bag of new goodies including a new tag - <canvas>. This tag is effectively like a piece of paper on your page onto which you can draw and this is what the majority of the RGraph library is based on. The drawing is done by JavaScript and there's a whole bunch of functions available to you to draw shapes and lines with.

Because <canvas> uses a "fire and forget" methodology there is no DOM for you to get references to shapes already drawn on the canvas - so you must remember the coordinates of the shapes yourself. It's because of this that the <canvas> tag is so fast.

Despite this though there is a Path2D object that has been added, along with other new features that have been specified by the W3C that will allow you to retain path information and test at a later time for hits etc. The Path2D object is described here. So on to the information!

The canvas element

The canvas state

Drawing rectangles

Path functions

Linedash options

Color options




Shadow properties

Pixel manipulation