Jon Rumsey

An online markdown blog and knowledge repository.


Project maintained by nojronatron Hosted on GitHub Pages — Theme by mattgraham

Notes From Various Resources on ChartJS and Canvas API

WebDesignerDepot Article on Chart.js

WebDesignerDepot.com article on chart-js

Rather than using tables to display data, use charts!

ChartJS makes creating and styling charts much easier.

To get started with Chart.js:

  1. Download it.
  2. Copy Chart.min.js into your css folder.
  3. Import Chart.min.js into your html page.

Overview

Article Credit: SARA VIEIRA, freelance Web Designer and Developer

Chart.js Home Page

ChartJS.org Docs

Chart.js is supported by most modern browsers, including:

Note: The dev team used BrowserStack to test the code against many browsers.

IE 11 is no longer supported.

Chart.js has a Slack channel for discussion, GitHub repo for bugs and commit/pr'ing, and the project is well documented and easy to follow.

Animation features allow fly-in or 'bouncy' charts. Much more fun than the status quo.

Resizing/responsiveness is possible however a specific set of configurations must be followed to avoid blurry charts or render errors.

Mozilla Developers Network Canvas API Basic Usage

MDN > Canvas API > Basic Usage

<canvas id='stock-chart' heigh='100px' width='100px'>Stock Chart is not available</canvas>

Mozilla Developers Network Canvas API Drawing Shapes

MDN > Canvas API > Drawing Shapes with Canvas

The drawing 'grid' (Coordinate Space) is how the canvas drawing space is described.

Coord (0,0) is at the top-left corner, so (x,y) pixels are targeted accordingly.

Two shapes are supported:

Draw Triangles using LineTo() and MoveTo().

Draw other objects or free-form using Paths and Arcs.

MoveTo() moves the 'pen' to a new location, to start drawing elsewhere on the canvas.

Use Loops to make many drawings!

Make quadratic or bezier shapes and patterns!

Mozilla Developers Network Canvas API Style and Color

MDN > Canvas API > Applying Styles and Colors

Color is added using fillStyle() and strokeStyle() methods.

Note: These methods are 'sticky', meaning once set, following drawing commands will use them, until the methods are changed again.

Transparency is possible using globalAlpha property or by assining a semi-transparent color to the stroke/fill style.

RGBA() fillStyle() properties provide a bit more control over the hue and brightness.
Lines can be styled with:

Mozilla Developers Network Canvas API Drawing Text

MDN > Canvas API > Drawing Text

Drawing text has its own set of methods:

Note: Prefixed APIs have been removed from FireFox and other Mozilla apps.

Back to index in readme