bhylu.com

Advertisements

JS Canvas

Canvas draws pixels through a rendering context. Supply a text alternative and account for the element drawing dimensions.

Where to run this

Use a local browser project for this example. It needs browser permissions, additional files, a server endpoint, or a library as described below. The restricted playground cannot provide those dependencies.

A practical example

JavaScript

// HTML: <canvas id="chart" width="320" height="160">Repair: 8; Wood: 5</canvas>
const context = document.getElementById("chart").getContext("2d");
context.fillStyle = "#17634c";
context.fillRect(20, 20, 240, 40);
context.fillRect(20, 80, 150, 40);

What happens

A local page draws two horizontal bars at different lengths.