An HTML5 canvas reference

A reference to the HTML5 canvas tag API functions and settings. There are examples provided which can help you to master the API. The RGraph blog also has more examples of using the canvas tag.

Learn how to use the canvas tag API

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 options

Pixel manipulation