All said programmers lazy, life is not lazy, such as shampoo, wash face, of course, also includes sharing. Here's a look at the pie chart I've drawn with H5 's new label canvas, which is randomly generated, generates 6 of equal numbers dynamically, and I do random data generation,
With the text, each share of the proportion on the display and opinions. , which is very good for analyzing data. The picture is as follows;
Canvas is a label provided by HTML5 to show the drawing effect. Canvas, Canvas. Used in HTML pages to show drawing effects. The first canvas was a proposal from Apple, which has been implemented in most browsers today.
Basic usage Syntax:
- Use the canvas label to create a single area of the page. You can set its width and height to set the size of the area.
- The width height of the default canvas is 300 and 400.
- Do not use CSS to set the width height, you should use HTML attributes.
- If the browser does not support the canvas label, it will be interpreted as a div tag. As a result, text is often embedded in the canvas to prompt the user's browser's ability.
- Canvas compatibility is very strong, as long as the support of the label, the basic functions are the same, so do not consider compatibility issues.
- Canvas itself cannot draw. is to use JavaScript to complete the drawing. The Canvas object provides an API for various drawing purposes.
Drawing steps
- Gets the
canvas
object.
- Invokes
getContext
a method that provides a string argument ‘2d‘
.
- The method returns an object of the
CanvasRenderingContext2D
type. The object provides basic drawing commands.
- Use
CanvasRenderingContext2D
the methods provided by the object to draw.
- Basic drawing Commands
Pie chart drawn with canvas, 6 equal, color random