小程序实现半环(弧形)进度条或者百分比
1.效果图如下

2.上代码
data: {
score:50
},
onLoad: function () {
this.setdetail()
},
setdetail(){
const query = this.createSelectorQuery()
query.select('#ring').boundingClientRect(res => {
this.drawRing('ring', res.width, res.height, this.data.score)
}).exec()
}
setjindutiao(){
drawRing: function (canvasId, width, height, angle) {
var context = wx.createCanvasContext(canvasId, this)
context.beginPath()
context.arc(width / 2, height - 60, width / 2 - 50, 1 * Math.PI, 3 * Math.PI)
context.setLineWidth(7)
context.setLineCap('round')
context.setStrokeStyle('#DFB157')
context.stroke()
context.beginPath()
context.arc(width / 2, height-60 , width / 2 - 50,Math.PI * ( 2.8/ 1),
Math.PI * (2.8 / 1) + angle / 100 * (Math.PI * 7 / 5))
context.setLineWidth(7)
context.setLineCap('round')
context.setStrokeStyle('#F05337')
context.stroke()
context.draw()
},
}
// wxml片段
<canvas id="ring" canvas-id="ring" class="progress-canvas" >
</canvas>
3. 图的大小是根据宽高设定的,自己设置好
.progress-canvas {
width: 100%;
height: 400;
position: relative;
}