小程序中canvas半圆统计

 

HTML代码

<canvas id="myCanvas{{index}}" canvas-id="myCanvas{{index}}" class="progress-canvas"></canvas>

CSS代码

.progress-canvas {width: 150rpx; height: 150rpx; position: absolute; top: -50rpx; right: -10rpx;}

js代码

const query = that.createSelectorQuery();
query.select('#myCanvas').boundingClientRect(res => {
     let surplusVal = 60;
     this.drawRing('myCanvas', res.width, res.height, surplusVal);
}).exec(); 

 圆的大小可以通过修改下面数字来改变

//绘制半圆
  drawRing(canvasId, width, height, angle){
    var context = wx.createCanvasContext(canvasId, this);
    // 外层圆环
    context.beginPath()
    context.arc(width / 2, height - 15, width / 2 - 10, 1 * Math.PI, 3 * Math.PI)
    context.setLineWidth(5)
    context.setLineCap('round')
    context.setStrokeStyle('#999')
    context.stroke()

    // 外层进度圆环
    context.beginPath()
    // 1.x轴 ,2y轴,3,半径,
    context.arc(width / 2, height-15 , width / 2 - 10,Math.PI * ( 2.8/ 1),
    Math.PI * (2.8 / 1) + angle / 100 * (Math.PI * 7 / 5))
    context.setLineWidth(5)
    context.setLineCap('round')
    context.setStrokeStyle('#ffcc66')
    context.stroke()
    context.draw()
  },

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值