簡體   English   中英

如何在html和css中創建多色圓圈

[英]How to create a multi colored circle in html and css

我想創建一個基於某些值划分為6個扇區的圓,扇區的角度取決於某個參數。 參數值越大,圓的弧度越大。

我理解它的方式可以通過制作一個具有這6個不同部分的圓形,然后在頂部放置另一個div來構建,這樣就產生了這種白色環效果。 我知道如何創建圓,但無法理解如何將其動態划分為不同顏色的扇區。

這甚至可以用CSS,使用Javascript是否存在解決方案。 任何幫助將深表感謝。

圈

HTML5 Canvas是要走的路。 以下是一些要學習的鏈接:

W3C規范

Kinetic.js

嘗試這樣的事情: http//html5.litten.com/graphing-data-in-the-html5-canvas-element-part-iv-simple-pie-charts/

應該注意的是,我發現曾經通過使用谷歌找到這個問題/答案: HTML5 Canvas餅圖

<!DOCTYPE html>
<html>
<head>
</head>
<body>

<canvas id="first" width="300" height="300" style="border:1px solid #000;">Your browser       does not support the HTML5 canvas tag
</canvas>

 <p>
  <select name="shapes" id="shapes">
     <option value="Square">Square</option>
     <option value="Circle">Circle</option>
  </select>
</p>
<p>
  <select name="bkcolour" id="bkcolour">
    <option>Red</option>
    <option>Black</option>
  </select>
</p>

<button onclick="drawshapes()">Try it</button>

<script>
    function drawTenSquare()
    {
   for(var i=0; i<10; i++)
   {
        var x=45;
    var y=25;
    var canvas =document.getElementById("first");
            var context=canvas.getContext("2d");
            context.fillStyle="#FF0000";
            context.fillRect(x+(i*15),y+(i*5),10,10);
   }
   }

   function drawTenCircle()
   {
    for(var i=0; i<10; i++)
    {
       var canvas=document.getElementById("first");
           var context=canvas.getContext("2d");
           context.beginPath();
           context.arc(95+(i*5),50+(i*2),40,0,2*Math.PI);
           context.stroke();
   }
  }

  function drawshapes()
  {
   var shape = document.getElementById("shapes")
   var index = shape.selectedIndex;
   var valindex = shape[index].value;

   if(valindex == "Square")
   {
    drawTenSquare();
   }
   else if(valindex == "Circle")
   {
    drawTenCircle();
   }
}
</script>

</body>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM