Reading Notes
Chart.js a javascript plugin
Create new html page with following
<head>
<meta charset="tf-8" />
<title> Chart.js demo</title>
<script src="Chart.min.js"></script>
</head>
<canvas id="lineChartId" width="600" height="400"></canvas>
Add script to retrieve the context of the canvas
<script>
var example = document.getElementById('lineChartId'). getContext('2d');
new Chart(example).Line(exampleData);
</script>
Provide the data
var exampleData = {
labels:["January", "February", "March", "April", "May", "June"],
datasets:[
{
fillColor: "rgba(172,194,132,0.4)",
strokeColor: "#Acc26D",
pointColor:"fff",
pointStrokeColor: "#9DB86D",
data: [203, 156, 99, 251, 305, 247]
}
]
}
Download link: https://www.chartjs.org/docs/latest/
<canvas>Fallback text</canvas>
tags will give the user a placeholder info if their browser doesn’t support chart.jsfillRect(x, y, width, height)
Draws a filled rectanglestrokeRect(x, y, width, height)
Draws a rectangular outlineclearRect(x, y, width, height)
Clears the specified area, making it fully transparentbeginPath()
Creates a new pathClosePath()
Adds a straight line to the path, going to the start of the current sub-pathstroke()
Draws a solid shape by filling the path’s content areamoveTo(X, Y)
Moves the pen to coordinates specified by x and yarc(x, y, radius, startAngle, endAngle, anticlockwise)
Draws an arc which is centered at (X,Y)
with radius r. Default direction is clockwisearcTo(x1, y1, x2, y2, radius)
Draws and arc with the given control points and radius, connected to the previous point by a straight line
function draw() {
var canvas = document.getElementByID('canvas');
if (canvas.getContext){
var ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.moveTo(75,50);
ctx.moveTo(100, 75);
ctx.moveTo(100,25);
ctx.fill();
}
}
Colors
fillStyle = color
sets the style used when filling shapesstrokeStyle = color
sst the style for shapes’ outlinesglobalAlpha
Sets the default transparency value for colors in the canvas elementLine Styles
lineWidth = value
sets the width of lines drawn in the futuerlineCap = type
sets the appearance of th ends of lineslineJoin = type
sets the appearance of the corners where lines meetmiterLimit = value
establishes a limit on the miter when two lines join at a sharp anglegetLineDash()
returns the current line dash pattern array containing an even number of non-negative numberssetLineDash(segments)
sets the current line dash patternlineDashOffset = value
specifies where to start a dash array on a lineGradients
createLinearGradient(x1,y1,x2,y2)
creates a linear gradient from start point to end pointcreateRadialGradient(x1, y1, r1, x2, y2, r2)
creates a radial gradient, parameters represent two circles one with its center at first coordinates and radius of r1 and other with center at second coordinates and radius of r2gradient.addColorStop(position, color)
Position is number between 0 and 1 defining relative position of each color, may have multiple color stopsText
fillText(text, x, y[, maxWidth])
fills a given text at the given position optionally it a max width drawstrokeText(text, x, y[, maxWidth])
strokes a given text at the given position and optionally with a maximum width draw