An online markdown blog and knowledge repository.
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:
<canvas>
element is used to set a new chart on the page.<script>
element to grab data for the chart.Article Credit: SARA VIEIRA, freelance Web Designer and Developer
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.
MDN > Canvas API > Basic Usage
<canvas>
element as an <img>
element but without src or alt attributes.<canvas id='stock-chart' heigh='100px' width='100px'>Stock Chart is not available</canvas>
canvas.getContext()
and use the result to render a canvas or something else.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!
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:
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.