About Canvas & Element & Chart.js

Basic usage of Canvas

Canvas is essentially an element that looks like an image but is empty (doesn’t have a source), unlike an image tag though, canvas tags require a closing tag. This space, can be decided using the width and height attributes, however, if none were set the default for a canvas is 300px wide and 150px high.

What Is The Chart??

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. They’re easier to look at and convey data quickly, but they’re not always easy to create

Drawing line chart

Drawing a pie chart

Patterns: To create patterns we use the createPattern(image, type) method. The types of patterns applied can be any of the below:

  1. repeat: Tiles the image in both vertical and horizontal directions.
  2. repeat-x: Tiles the image horizontally but not vertically.
  3. repeat-y: Tiles the image vertically but not horizontally.
  4. no-repeat: Doesn’t tile the image. It’s used only once.

HTML Canvas Graphics

What is HTML Canvas?

-The HTML element is used to draw graphics, on the fly, via JavaScript. The <canvas> element is only a container for graphics. You must use JavaScript to actually draw the graphics. Canvas has several methods for drawing paths, boxes, circles, text, and adding images.

Canvas Examples

A canvas is a rectangular area on an HTML page. By default, a canvas has no border and no content.

```

Note:

  1. Always specify an id attribute (to be referred to in a script), and a width and height attribute to define the size of the canvas.
  2. The canvas element takes two attributes which are the width and height attributes.
  3. The canvas can be style the same way other elements are. But the canvas starts out as transparent and needs to be styled.
  4. In order to create the chart, you need to use the canvas element in the HTML file.
  5. The canvas has a grid that actually has the position of the canvas and we can control it.

Table Of Content