Charts for displaying data visually . They are easier to look at and convey data quickly but not always to create.
Chart.js a great way to get started with charts.
java Script uses HTML5 canvas element to draw the graph.
setting up charts:
canvas element has only 2 attributes (width & height), id attribute to identify it in a script.
canvas can be styled such as (margin, border, background … ).
The canvas is blank. A script first needs to access the rendering context and draw on it. The
fillRect(x, y, width, height) ——-> Draws a filled rectangle. strokeRect(x, y, width, height) —–> Draws a rectangular outline. clearRect(x, y, width, height)——-> Clears the specified rectangular area, making it fully transparent.
beginPath() —–> Creates a new path. Once created, future drawing commands are directed into the path and used to build the path up. Path methods —-> Methods to set different paths for objects. closePath() —–> Adds a straight line to the path, going to the start of the current sub-path. stroke() ——–> Draws the shape by stroking its outline. fill() ———-> Draws a solid shape by filling the path’s content area. moveTo(x, y) —-> Moves the pen to the coordinates specified by x and y.
For drawing straight lines, use the lineTo() method.
lineTo(x, y) —–> Draws a line from the current drawing position to the position specified by x and y.
fillStyle = color ——> Sets the style used when filling shapes. strokeStyle = color —-> Sets the style for shapes’ outlines.
lineWidth = value —–> Sets the width of lines drawn. lineCap = type ——–> Sets the appearance of the ends of lines. lineJoin = type ——-> Sets the appearance of the “corners” where lines meet. miterLimit = value —-> Establishes a limit on the miter when two lines join at a sharp angle, to let you control how thick the junction becomes. getLineDash() ———> Returns the current line dash pattern array containing an even number of non-negative numbers. setLineDash(segments) –> Sets the current line dash pattern. lineDashOffset = value –> Specifies where to start a dash array on a line.
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.
font = value ———-> The current text style being used when drawing text. This string uses the same syntax as the CSS font property. The default font is 10px sans-serif. textAlign = value ——> Text alignment setting. Possible values: start, end, left, right or center. The default value is start. textBaseline = value —> Baseline alignment setting. Possible values: top, hanging, middle, alphabetic, ideographic, bottom. The default value is alphabetic. direction = value ——> Directionality. Possible values: ltr, rtl, inherit. The default value is inherit.
Thank You
Sukina AbuHammad