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)

相关文章

显卡天梯图2024最新版,显卡是电脑进行图形处理的重要设备,...
初始化电脑时出现问题怎么办,可以使用win系统的安装介质,连...
todesk远程开机怎么设置,两台电脑要在同一局域网内,然后需...
油猴谷歌插件怎么安装,可以通过谷歌应用商店进行安装,需要...
虚拟内存这个名词想必很多人都听说过,我们在使用电脑的时候...