canvas环型比例图

dom部分

 <div class='process-container circle-progress'>
                <canvas id="canvas" class="canvas" width="100%" height="100%"></canvas>
            </div>

js

 DrawRound(percent) {
            const canvas = document.getElementById("canvas")
            const ctx = canvas.getContext("2d");
            const box=document.getElementsByClassName("process-container")[0]
            canvas.width =box.clientHeight
            canvas.height=box.clientHeight
            const cx = canvas.width / 2, cy = canvas.height / 2, r = (canvas.width / 4) + 16
            var img = new Image();     //创建图片对象
            import("./images/Union.png").then(res => {
                img.src = res.default
            })     //设置绘制图像路径
            img.onload = function () {
                ctx.drawImage(img, cx / 2-10 , cy / 2 -10 , cx + 20, cy + 20)
            }
            //外边框
            var img1 = new Image();     //创建图片对象
            import("./images/outline.png").then(res => {
                img1.src = res.default
            })     //设置绘制图像路径
            img1.onload = function () {
                ctx.drawImage(img1, -2, -2, cx * 2, cy * 2)
            }
            //环形图的进度条
            ctx.beginPath();
            ctx.arc(cx , cy , r, Math.PI / 2, Math.PI / 2 - percent * (Math.PI * 2), false);
            ctx.lineWidth = 5;
            ctx.lineCap = "round";
            ctx.strokeStyle = "#06FFA5";
            ctx.stroke();

            ctx.beginPath();
            ctx.arc(cx + 2, cy, r, Math.PI / 2 - percent * (Math.PI * 2) + 0.3, Math.PI / 2 - 0.3, false);
            ctx.lineWidth = 5;
            ctx.lineCap = "round";
            ctx.strokeStyle = "#f0f6f9";
            ctx.stroke();

            ctx.font="12px Open Sans-SemiBold, Open Sans"
            ctx.fillStyle = "#ffffff";
            ctx.fillText("设备总数",cx-25,cy-15);
        },
        //清空画布
        clearCanvas(){
            const theCanvas = document.getElementById("canvas")
            const ctx = canvas.getContext("2d");
            var w = theCanvas.width;
            var h = theCanvas.height;
            ctx.clearRect(0, 0, w, h);
        },
//比如在组件挂载时启动定时器
let count=0
setInterval(()=>{
count++
this.clearCanvas()
this.DrawRound(0.1*count)
},3000)

相关文章

学习编程是顺着互联网的发展潮流,是一件好事。新手如何学习...
IT行业是什么工作做什么?IT行业的工作有:产品策划类、页面...
女生学Java好就业吗?女生适合学Java编程吗?目前有不少女生...
Can’t connect to local MySQL server through socket \'/v...
oracle基本命令 一、登录操作 1.管理员登录 # 管理员登录 ...
一、背景 因为项目中需要通北京网络,所以需要连vpn,但是服...