日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

小程序 mpvue 使用canvas绘制环形图表

發(fā)布時間:2023/12/10 vue 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 小程序 mpvue 使用canvas绘制环形图表 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本來想用css3來實現(xiàn),發(fā)現(xiàn)輪廓邊上殘影嚴重,所以直接用小程序的canvas使用來。
最終效果如下:

我的整頁代碼如下,里面已經(jīng)寫出備注來。

<template><div class="statistic"><canvas canvas-id="runCanvas" id="runCanvas" class='canvas'></canvas></div> </template> <script>export default {data() {return {}},methods: {run(x0, y0, nowPercent) {// 1° 設置配置參數(shù)// 環(huán)形的線寬度const lineWidth = 16;// 半徑const radius = x0 - lineWidth;// 起始弧const sAngle = -0.5 * Math.PI;// 終止弧let eAngle = (2 * Math.PI / 100 * nowPercent) - 0.5 * Math.PI;// 2° 畫圓環(huán)陰影this.ctx2.setLineWidth(16);this.ctx2.setStrokeStyle('#d2d2d2');this.ctx2.setLineCap('round')this.ctx2.arc(x0, y0, radius, 0, 2 * Math.PI, false);//對當前路徑進行描this.ctx2.stroke();// 3° 畫圓環(huán)激活高亮部分this.ctx2.beginPath();//開始一個新的路徑this.ctx2.setLineWidth(16);this.ctx2.setStrokeStyle('#00D49F');this.ctx2.setLineCap('round')this.ctx2.arc(x0, y0, radius, sAngle, eAngle, false);this.ctx2.stroke();// 4° 設置環(huán)心字體this.ctx2.beginPath();// 字體大小 注意不要加引號this.ctx2.font = 'normal bold 40px sans-serif';// 字體顏色this.ctx2.setFillStyle("#00D49F");// 字體位置this.ctx2.setTextAlign("center");// 字體對齊方式this.ctx2.setTextBaseline("middle");// 文字內(nèi)容和文字坐標this.ctx2.fillText(nowPercent + "%", x0, y0);// 5°最后通過draw把上面的描述繪制出來this.ctx2.draw();},draw(id, percent) {this.ctx2 = wx.createCanvasContext(id);const that = this;wx.createSelectorQuery().select('#' + id).boundingClientRect(function (rect) { //監(jiān)聽canvas的寬高// 獲取圓心坐標var x0 = parseInt(rect.width / 2); //獲取canvas寬的的一半var y0 = parseInt(rect.height / 2); //獲取canvas高的一半,// 開始畫畫that.run(x0, y0, percent);}).exec();},},mounted() {this.draw('runCanvas', 50);} } </script><style lang="less" scoped>.canvas {width: 150px;height: 150px;position: absolute;left: 0;top: 0;bottom: 0;right: 0;margin: auto auto;z-index: 99;} </style> <style lang="less">page {background: white;} </style>

總結(jié)

以上是生活随笔為你收集整理的小程序 mpvue 使用canvas绘制环形图表的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。