• <tbody id="9je1r"></tbody><tbody id="9je1r"><acronym id="9je1r"><rp id="9je1r"></rp></acronym></tbody>
      • <acronym id="9je1r"><acronym id="9je1r"><rp id="9je1r"></rp></acronym></acronym>

        亚洲无码Aⅴ,视频1页精品,欧美系列一区二区,曰韩色999

        div里利用canvas進行一個餅形圖的繪制

        2017/2/23 8:30:44   閱讀:2324    發(fā)布者:2324
        <!DOCTYPE html> 
        <html lang="en"> 
        <head> 
            <meta charset="UTF-8"> 
            <title>繪制餅形圖。</title> 
            <style> 
                canvas{ 
                    border: 1px solid green; 
                } 
            </style> 
        </head> 
        <body> 
            <!-- 繪制餅形圖 --> 
            <canvas width="500" height="500" id="canvas"></canvas> 
        </body> 
        <script> 
            var canvas = document.getElementById(’canvas’); 
            var ctx = canvas.getContext(’2d’); 
            function toAngle(radian){ 
                return radian*180/Math.PI; 
            } 
            function toRadian(angle){ 
                return angle*Math.PI/180; 
            } 
            /*將餅狀圖畫出來*/ 
            var colors = ’green,yellow,pink,blue,red,lightgreen,lightblue’.split(’,’); 
            var text = ’HTML5,Canvas,Javascript,Css3,Ajax,框架封裝,jQuery與移動Web’.split(’,’); 
            var x0 = canvas.width/2, 
                y0 = canvas.height/2, 
                radius = 100, 
                start = -5, 
                distance = 20, 
                padding = 5, 
                step = 360/colors.length; 
            for(var i = 0 ; i < colors.length ; i ++){ 
                ctx.beginPath(); 
                ctx.fillStyle = colors[i]; 
                ctx.moveTo(x0,y0); 
                ctx.arc(x0,y0,radius,toRadian(start),toRadian(start+=step)); 
                ctx.fill(); 
                /*畫斜線*/ 
                ctx.beginPath(); 
                ctx.strokeStyle = colors[i]; 
                var x1 = x0 + (radius+distance)*Math.cos(toRadian(( start-step/2 ))), 
                    y1 = y0 + (radius+distance)*Math.sin(toRadian(( start-step/2 ))); 
                ctx.moveTo(x0,y0); 
                ctx.lineTo(x1,y1); 
                ctx.stroke(); 
                /*寫文字*/ 
                ctx.beginPath(); 
                ctx.fillStyle = colors[i]; 
                var textX = x1, 
                    textY = y1; 
                if(start-step/2 > 90 && start-step/2 < 270){ 
                    ctx.textAlign = ’right’; 
                    textX = textX - padding; 
                }else{ 
                    ctx.textAlign = ’left’; 
                    textX = textX + padding; 
                } 
                ctx.fillText(text[i],textX,textY-padding/2); 
                /*畫直線*/ 
                ctx.beginPath(); 
                ctx.moveTo(x1,y1); 
                //計算文字的寬度 
                var length = ctx.measureText( text[ i ] ).width 
                if(start-step/2 > 90 && start-step/2 < 270){ 
                    x1 += -2*padding-length; 
                }else{ 
                    x1 += 2*padding + length; 
                } 
                ctx.lineTo(x1,y1); 
                ctx.stroke(); 
                /*畫餅形圖*/ 
                /*ctx.beginPath(); 
                ctx.fillStyle = colors[i]; 
                ctx.moveTo(x0,y0); 
                ctx.arc(x0,y0,radius,toRadian(start),toRadian(start+=step)); 
                ctx.fill();*/ 
            } 
        </script> 
        </html>

         

        亚洲无码Aⅴ,视频1页精品,欧美系列一区二区,曰韩色999
            • <tbody id="9je1r"></tbody><tbody id="9je1r"><acronym id="9je1r"><rp id="9je1r"></rp></acronym></tbody>
            • <acronym id="9je1r"><acronym id="9je1r"><rp id="9je1r"></rp></acronym></acronym>
              东乌珠穆沁旗| 遵化市| 虎林市| 县级市| 保定市| 黔西县| 龙南县| 大竹县| 丰城市| 墨竹工卡县| 两当县| 台湾省| 常熟市| 宁德市| 东乡| 明水县| 辽阳县| 岑巩县| 南溪县| 丹巴县| 怀集县| 洪雅县| 兴化市| 东乌| 滦平县| 桑植县| 云南省| 黑水县| 马关县| 三穗县| 赫章县| 泗阳县| 郁南县| 浦县| 贺兰县| 集贤县| 扬州市| 保德县| 焦作市| 申扎县| 锡林浩特市|