Article Summaries

Article 1: EASILY CREATE STUNNING ANIMATED CHARTS WITH CHART.JS

Setting up

Charts

Drawing a line chart

Charts

Next, we need to write a script that will retrieve the context of the canvas, so add this to the foot of your body element:

Charts

Inside the same script tags we need to create our data, in this instance it’s an object that contains labels for the base of our chart and datasets to describe the values on the chart. Add this immediately above the line that begins ‘var buyers=’:

Charts

If you test your file in a browser you’ll now see a cool animated line graph.

Article 2: Basic usage of canvas

Canvas

Fallback content

-The <canvas> element differs from an <img> tag in that, like for <video>, <audio>, or <picture> elements, it is easy to define some fallback content, to be displayed in older browsers not supporting it, like versions of Internet Explorer earlier than version 9 or textual browsers. You should always provide fallback content to be displayed by those browsers.

Canvas

The rendering context

Canvas

Article 3: Drawing shapes with canvas

The grid

Canvas

Drawing rectangles

First let’s look at the rectangle. There are three functions that draw rectangles on the canvas:

Canvas

Canvas

In upcoming pages we’ll see two alternative methods for clearRect(), and we’ll also see how to change the color and stroke style of the rendered shapes.

Unlike the path functions we’ll see in the next section, all three rectangle functions draw immediately to the canvas.

Article 4: Applying styles and colors

A fillStyle example

Canvas Canvas

A globalAlpha example

Canvas Canvas

Article 5: Drawing text

A fillText example

Canvas Canvas

A strokeText example

Canvas Canvas

A textBaseline example

Canvas Canvas References:

Main page