Charts are far better for displaying data visually than tables and have the added benefit that no one is ever going to press-gang them into use as a layout tool.
Setting up:
<script src='Chart.min.js'></script>
Drawing a line char:t
<canvas id="buyers" width="600" height="400"></canvas>
Drawing a pie chart:
<canvas id="countries" width="600" height="400"></canvas>
Drawing a bar chart:
<canvas id="income" width="600" height="400"></canvas>
At first sight a <canvas> looks like the element, with the only clear difference being that it doesn’t have the src and alt attributes. Indeed, the <canvas> element has only two attributes, width and height.
The <canvas> element can be styled just like any normal image
The <canvas> element creates a fixed-size drawing surface that exposes one or more rendering contexts, which are used to create and manipulate the content shown.
The fallback content is displayed in browsers which do not support
Drawing rectangles
<canvas> only supports two primitive shapes: rectangles and paths
fillRect(x, y, width, height)
Draws a filled rectangle.
strokeRect(x, y, width, height)
Draws a rectangular outline.
clearRect(x, y, width, height)
Clears the specified rectangular area, making it fully transparent.
functions used to perform these steps:
beginPath()
Creates a new path. Once created, future drawing commands are directed into the path and used to build the path up.Path methods
Methods to set different paths for objects.closePath()
Adds a straight line to the path, going to the start of the current sub-path.stroke()
Draws the shape by stroking its outline.fill()
Draws a solid shape by filling the path’s content area.moveTo(x, y)
Moves the pen to the coordinates specified by x and y.(
## Applying styles and colors
globalAlpha = transparencyValue Applies the specified transparency value to all future shapes drawn on the canvas. The value must be between 0.0 (fully transparent) to 1.0 (fully opaque). This value is 1.0 (fully opaque) by default.
## Drawing text
The canvas rendering context provides two methods to render text:
fillText(text, x, y [, maxWidth])
Fills a given text at the given (x,y) position. Optionally with a maximum width to draw.strokeText(text, x, y [, maxWidth])
Strokes a given text at the given (x,y) position. Optionally with a maximum width to draw.