Detailed description of the canvas polygon (Spider chart) painting example, detailed description of the canvas painting example

Source: Internet
Author: User
Tags drawtext

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.