canvas實現的簡單餅狀圖程式碼例項
分享一段程式碼例項,它利用canvas實現了簡單的餅狀圖效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> </head> <body> <canvas id="canvas" width="600" height="600"></canvas> <script> var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); function rand(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } function bing(deg) { this.r = rand(100, 150); this.color = "rgba(" + rand(0, 256) + "," + rand(0, 256) + "," + rand(0, 256) + "," + Math.random() + ")"; ctx.beginPath(); ctx.fillStyle = this.color; ctx.moveTo(250, 250); ctx.arc(250, 250, this.r, deg, deg + Math.PI / 4, false); ctx.closePath(); ctx.stroke(); ctx.fill(); } var deg = 0; for (var i = 0; i < 8; i++) { bing(deg) deg += Math.PI / 4; } </script> </body> </html>
相關文章
- highcharts實現的餅狀圖程式碼例項
- canvas實現的簡單塗鴉板程式碼例項Canvas
- canvas實現的簡單畫板效果程式碼例項Canvas
- canvas實現的圖片縮放程式碼例項Canvas
- canvas實現的刮刮樂程式碼例項Canvas
- canvas簡單封裝一個echarts實現不了的餅圖Canvas封裝Echarts
- jQuery實現的簡單投票簡單程式碼例項jQuery
- javascript實現的圖片簡單切換程式碼例項JavaScript
- CSS實現的柱狀圖效果例項程式碼CSS
- canvas實現的美猴王程式碼例項Canvas
- angularJS結合canvas實現的畫圖程式碼例項AngularJSCanvas
- canvas簡單徑向漸變程式碼例項Canvas
- canvas畫圖程式碼例項Canvas
- canvas實現的旋轉的太極圖效果程式碼例項Canvas
- canvas實現的驗證碼效果程式碼例項Canvas
- html實現簡單ListViews效果的例項程式碼HTMLView
- javascript實現的動畫效果簡單例項程式碼JavaScript動畫單例
- canvas實現的變幻線程式碼例項Canvas線程
- canvas實現的多邊形程式碼例項Canvas
- canvas實現的千輪眼程式碼例項Canvas
- canvas實現的鋸齒效果程式碼例項Canvas
- canvas實現的鐘表效果程式碼例項Canvas
- EasyUI實現的form表單提交簡單程式碼例項UIORM
- javascript實現的簡單驗證碼效果程式碼例項JavaScript
- Canvas(3)---繪製餅狀圖Canvas
- 利用canvas實現的驗證碼效果程式碼例項Canvas
- jQuery實現的自動播放簡單程式碼例項jQuery
- css實現的div旋轉簡單程式碼例項CSS
- js實現的字串簡單編碼和解碼程式碼例項JS字串
- canvas實現的貪吃蛇遊戲程式碼例項Canvas遊戲
- canvas實現的雪花飄落效果程式碼例項Canvas
- canvas實現的藍色雨滴效果程式碼例項Canvas
- canvas實現的彈力小球效果程式碼例項Canvas
- Python實現簡單網頁圖片抓取完整程式碼例項Python網頁
- canvas實現煙花燃放效果程式碼例項Canvas
- js自定義實現的簡單編碼和解碼程式碼例項JS
- canvas繪製網狀圓圈程式碼例項Canvas
- canvas實現的隨機生成漂浮小球程式碼例項Canvas隨機