Linear Area Chart tutorial Based on HTML5 Canvas

Source: Internet
Author: User

Linear Area Chart tutorial Based on HTML5 Canvas
Next we will briefly introduce the process and source code for implementing this HTML5 chart. HTML code: <canvas id = "cvs" width = "600" height = "250"> [No canvas support] </canvas> A simple canvas tag, our charts are drawn on the canvas. Since this chart is based on RGraph, we also need to reference the js script of RGraph and the jquery Class Library: copy the Code <script src = ".. /libraries/RGraph. common. core. js "> </script> <script src = ".. /libraries/RGraph. common. effects. js "> </script> <script src = ".. /libraries/RGraph. common. dynamic. js "> </script> <script src = ".. /libraries/RGraph. common. tooltips. js "> </script> <script src = ".. /libraries/RGraph. drawing. poly. js "> </script> <script src = ".. /libraries/RGraph. line. js "> </script> <script src = ".. /libraries/jquery. min. js "> </script>: copy the code var d1 = []; var d2 = []; var val = 47; // Create the data for (var I = 0; I <100; I + = 1) d1 [I] = RGraph. random (100); for (var I = 0; I <; I + = 1) d2 [I] = RGraph. random (25, 35); var line = new RGraph. line ('cvs ', d1, d2 ). set ('background. grid. autofit. numhlines ', 10 ). set ('hmargin ', 10 ). set ('filened', true ). set ('fillstyle', 'red '). set ('filled. range ', true ). set ('filled. range. threshold ', 40 ). set ('filled. range. threshold. colors ', ['rgba (0.5, 0, 255)', 'rgba (0.5,) ']). set ('labels', ['q1', 'q2 ', 'q3', 'q4']). set ('colors ', ['Gray', 'Gray ']). set ('numxticks ', 8 ). set ('linewidth', 1 ). set ('ymax ', 60) RGraph. effects. line. jQuery. trace (line); var coords = [] for (var I = 0; I <(line. coords. length/2); I + = 1) {coords. push (line. coords [I])} for (var I = (line. coords. length-1); I> = (line. coords. length/2); I-= 1) {coords. push (line. coords [I])} var poly = new RGraph. drawing. poly ('cvs ', coords ). set ('fillstyle', 'rgba (0, 0, 0, 0 )'). set ('strokestyle', 'rgba (0, 0, 0, 0 )'). set ('tooltids', ['The range chart']). set ('highlight. fill ', 'rgba (255,255,255, 0.3 )'). draw ();

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.