- Charts are better for displaying data
- They’re easier to look at and convey data quickly
We Can use ChartJs a JavaScript plugin that uses HTML5’s canvas element to draw the graph onto the page and the chart
types we can make using chart js are :
- line chart
- bar chart
- radar chart
- radar chart
- doughnut and pie chart
- polar area chart
- bubble chart
- scatter chart
- area chart
- mixed chart types
- ChartJs have the way how to Setting up chart in the website
-
The
<canvas>element has only two attributes,widthandheight -
The
<canvas>element can be styled just like any normal image -
Browsers that don't support
<canvas>will ignore the container and render the fallback content inside it -
the
<canvas>element requires the closing tag(</canvas>)
- we can use the canvas to draw shaps like rectangles, triangles, lines, arcs and curves and we can use the canvas with chart
example
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);
}
}
fillStyle = color
strokeStyle = color
example
ctx.fillStyle = 'orange';
ctx.strokeStyle = 'rgba(255, 0, 0, 0.5)';
- The canvas rendering context provides two methods to render text:
fillText(text, x, y [, maxWidth]): Fills a given text at the given (x,y) position. Optionally with a maximum width to draw.
strokeText(text, x, y [, maxWidth]):Strokes a given text at the given (x,y) position. Optionally with a maximum width to draw.
- a
fillTextexample
function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
ctx.font = '48px serif';
ctx.fillText('Hello world', 10, 50);
}
- a
strokeTextexample
function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
ctx.font = '48px serif';
ctx.strokeText('Hello world', 10, 50);
}
- There are some more properties which let us adjust the way the text gets displayed on the canvas
font = value
textAlign = value
textBaseline = value
direction = value