Detailed description of the canvas polygon (Spider chart) painting example, detailed description of the canvas painting example
The painting method of the spider graph:
Before starting, we need to know how canvas draws images. The canvas element is used to draw images on webpages. HTML5 canvas elements use JavaScript to draw 2D images on webpages. On the canvas of the rectangle area, each pixel is controlled. JavaScript is used to draw 2D images and render them pixel by pixel. You can use the canvas Element to draw paths, rectangles, circles, characters, and add images in multiple ways.
* Note !!! The canvas label itself does not have the drawing function. It can only use JavaScript to draw images on webpages.
As follows:
1. initialize js Code
// Initialize (function () {var canvas = document. createElement ('canvas '); document. body. appendChild (canvas); canvas. height = mH; canvas. width = mW; mCtx = canvas. getContext ('2d '); drawPolygon (mCtx); // draw the polygon edges drawLines (mCtx); // draw the vertex link drawText (mCtx); // draw the text drawRegion (mCtx ); // draw data drawCircle (mCtx); // draw data dots })();
In the code above, you can use an immediate execution function to initialize all the settings. For the painting of the canvas positive hexagonal, see draw a positive hexagonal canvas.
In the spider diagram, we can split it up and draw complete individual components by drawing hexagonal, straight lines, and circles. Then, we can call and draw them in a unified way.
The source code is shown below:
<! DOCTYPE html>
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.