View on GitHub

reading-notes

Web Designer Depot Article

Chart.js

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Chart.js demo</title>
        <script src='Chart.min.js'></script>
    </head>
    <body>
    </body>
</html>

Drawing a line chart

Instead of me sumerizing this badly just go HERE

Canavas API

Basic Usage

Drawing Shapes with Canvas

  1. fillRect(x, y, width, height)
    • Draws a filled rectangle.
  2. strokeRect(x, y, width, height)
    • Draws a rectangular outline.
  3. clearRect(x, y, width, height)
    • Clears the specified rectangular are, making it fully transparent.
function draw() {
  var canvas = document.getElementById('canvas');
  if (canvas.getContext) {
    var ctx = canvas.getContext('2d');

    ctx.fillRect(25, 25, 100, 100);
    ctx.clearRect(45, 45, 60, 60);
    ctx.strokeRect(50, 50, 50, 50);
  }
}

Way more shapes Applying styles and colors

  1. fillStyle = color
    • Sets the style used when filling shapes.
  2. strokeStyle = color
    • Sets the style for shapes’ outlines.

more here

Drawing Text

  1. fillText(text, x, y [, maxWidth])
    • Fills a given text at the given (x,y) position. Optionally with a maximum width to draw.
function draw() {
  var ctx = document.getElementById('canvas').getContext('2d');
  ctx.font = '48px serif';
  ctx.fillText('Hello world', 10, 50);
}
  1. strokeText(text, x, y [, maxWidth])
    • Strokes a given text at the given (x,y) position. Optionally with a maximum width to draw.
function draw() {
  var ctx = document.getElementById('canvas').getContext('2d');
  ctx.font = '48px serif';
  ctx.strokeText('Hello world', 10, 50);
}

More Here

Back to Homepage