zoukankan      html  css  js  c++  java
  • 画圆环,Canvas百分比环状图

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Canvas progress</title>
    </head>
    <body>
        <canvas id="process" width="200" height="200"></canvas>
        <script>
            (function (){
                var c = document.getElementById('process'),
                    process = 0,
                    ctx = c.getContext('2d');
     
                // 画灰色的圆
                ctx.beginPath();
                ctx.arc(100, 100, 80, 0, Math.PI*2);
                // ctx.closePath();
                ctx.strokeStyle  = 'green';
                ctx.stroke();
     
                // 画红色的圆
                ctx.beginPath();
                ctx.arc(100, 100, 70, 0, Math.PI*2);
                // ctx.closePath();
                ctx.fillStyle  = 'red';
                ctx.fill();
     
                function animate(){
                    requestAnimationFrame(function (){
                        process = process + 1;
                        drawCricle(ctx, process);
                        if (process < 90) {
                            animate();
                        }
                    });
                }
     
                function drawCricle(ctx, percent){
                    // 画进度环
                    ctx.beginPath();
                    ctx.moveTo(100, 100);  
                    ctx.arc(100, 100, 80, Math.PI * 1.5, Math.PI * (1.5 + 2 * percent / 100 ));
                    ctx.closePath();
                    ctx.fillStyle = 'yellow';
                    ctx.fill();
     
                    // 画内填充圆
                    ctx.beginPath();
                    ctx.arc(100, 100, 60, 0, Math.PI * 2);
                    ctx.closePath();
                    ctx.fillStyle = '#fff';
                    ctx.fill();
     
                    // 填充文字
                    ctx.font = "bold 20pt Microsoft YaHei"; 
                    ctx.fillStyle = '#333';
                    ctx.textAlign = 'center';  
                    ctx.textBaseline = 'middle';  
                    ctx.moveTo(100, 100);  
                    ctx.fillText(process + '%', 100, 100);
                }
     
                animate();
            }());
        </script>
    </body>
    </html>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Canvas progress</title>
    </head>
    <body>
        <canvas id="process" width="300" height="300"></canvas>
        <script>
            (function (){
                var c = document.getElementById('process'),
                    process = 0,
                    ctx = c.getContext('2d');
     
                function animate(){
                    requestAnimationFrame(function (){
                        process = process + 1;
                        drawCricle(ctx, process);
                        if (process < 75) {
                            animate();
                        }
                    });
                }
     
                function drawCricle(ctx, percent){
                    // 画进度环
                    ctx.beginPath();
                    ctx.moveTo(100, 100);
                    ctx.arc(100, 100, 80, Math.PI * 1.5, Math.PI * (1.5 + 2 * percent / 100 ));
                    ctx.closePath();
                    ctx.fillStyle = '#108EE9';
                    ctx.fill();
     
                    // 画第一层灰色的圆
                ctx.beginPath();
                ctx.arc(100, 100, 70, 0, Math.PI*2);
                // ctx.closePath();
                ctx.fillStyle  = '#ededed';
                ctx.fill();
                // 画第二层白色的圆
                ctx.beginPath();
                ctx.arc(100, 100, 65, 0, Math.PI*2);
                // ctx.closePath();
                ctx.fillStyle  = '#fcfcfc';
                ctx.fill();
     
                    // 画内填充圆
                    ctx.beginPath();
                    ctx.arc(100, 100, 55, 0, Math.PI * 2);
                    ctx.closePath();
                    ctx.fillStyle = '#FAFCFC';
                    ctx.fill();
     
                // 画灰色的框
                ctx.beginPath();
                ctx.arc(100, 100, 55, 0, Math.PI*2);
                // ctx.closePath();
                ctx.strokeStyle  = '#f2f2f2';
                ctx.stroke();
     
                    // 填充文字
                    ctx.font = "bold 20pt Microsoft YaHei";
                    ctx.fillStyle = '#DA4816';
                    ctx.textAlign = 'center';
                    ctx.textBaseline = 'middle';
                    ctx.moveTo(100, 100);
                    ctx.fillText(process + '%', 100, 80);
     
                    ctx.fillStyle = '#aaa';
                    ctx.font="10px Georgia";
                    ctx.fillText("销售目标完成度",100,100);
     
                    // ctx.font="10px Georgia";
                    ctx.fillText("集团内排名",100,120);
     
                    ctx.fillStyle = '#DA4816';
                    ctx.font="10px Georgia";
                    ctx.fillText("1",100,140);
                }
     
                animate();
            }());
        </script>
    </body>
    </html>
  • 相关阅读:
    记一次网络实践
    python中得公有和私有——私有函数和公开函数_补充完整
    机器学习 之LightGBM算法
    机器学习 之XGBoost算法
    机器学习 之梯度提升树GBDT
    机器学习 之KNN近邻法
    机器学习之 XGBoost和LightGBM
    《剑指offer》 之二叉树
    随机森林RF、XGBoost、GBDT和LightGBM的原理和区别
    机器学习之决策树_CART算法
  • 原文地址:https://www.cnblogs.com/hellofangfang/p/14870077.html
Copyright © 2011-2022 走看看