SVG圈

2017-08-11 72 views
0

我试图使用SVG做一个饼图,所以我发现这个codepen有一个动画饼图SVG圈

我想50×使这个饼图20×20,而不是50,所以我想我可以改变宽度和高度,然后改变半径和中心点的一半。

我还将css中的笔画宽度更改为20,将圆周更改为63(2 x pie x 10),因此我不确定还需要更改哪个方块才能使方块变成圆圈。

但是,我得到一个奇怪的错误,在馅饼片变成一个正方形:click on the 100% button

有没有办法让第二个圆圈再次变成圆形?

我已经包含了下面的代码片段,但它不允许scss,所以我无法让它复制笔,但它证明了方形问题。

body { 
 
    /* Appearance */ 
 
    background-color: #2c333b; 
 
} 
 

 
a, h5, h3 { 
 
    /* Display & Box Model */ 
 
    margin: 10px 0; 
 
    /* Text */ 
 
    font-family: sans-serif; 
 
    font-weight: normal; 
 
    letter-spacing: 1px; 
 
    /* Appearance */ 
 
    color: #fff; 
 
} 
 

 
.svg { 
 
    /* Appearance */ 
 
    transform: rotate(-90deg); 
 
} 
 

 
.circle { 
 
    /* Appearance */ 
 
    fill: #fdded9; 
 
} 
 

 
#pie { 
 
    /* Appearance */ 
 
    stroke: #ff4081; 
 
    stroke-dasharray: 0 63; 
 
    stroke-width: 20; 
 
    transition: stroke-dasharray .2s linear; 
 
} 
 
#pie.percent-10 { 
 
    stroke-dasharray: 6.3 63; 
 
} 
 
#pie.percent-20 { 
 
    stroke-dasharray: 12.6 63; 
 
} 
 
#pie.percent-30 { 
 
    stroke-dasharray: 18.9 63; 
 
} 
 
#pie.percent-40 { 
 
    stroke-dasharray: 25.2 63; 
 
} 
 
#pie.percent-50 { 
 
    stroke-dasharray: 31.5 63; 
 
} 
 
#pie.percent-60 { 
 
    stroke-dasharray: 37.8 63; 
 
} 
 
#pie.percent-70 { 
 
    stroke-dasharray: 44.1 63; 
 
} 
 
#pie.percent-80 { 
 
    stroke-dasharray: 50.4 63; 
 
} 
 
#pie.percent-90 { 
 
    stroke-dasharray: 56.7 63; 
 
} 
 
#pie.percent-100 { 
 
    stroke-dasharray: 63 63; 
 
} 
 

 
.wrapper { 
 
    /* Positioning */ 
 
    position: absolute; 
 
    top: 50%; 
 
    left: 50%; 
 
    /* Display & Box Model */ 
 
    width: 100px; 
 
    /* Appearance */ 
 
    -moz-transform: translate(-50%, -50%); 
 
    -ms-transform: translate(-50%, -50%); 
 
    -webkit-transform: translate(-50%, -50%); 
 
    transform: translate(-50%, -50%); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="wrapper"> 
 
\t <svg width="20" height="20" class="svg"> 
 
\t \t <circle r="10" cx="10" cy="10" class="circle"/> 
 
\t \t <circle id="pie" r="10" cx="10" cy="10" class="circle percent-100"/> 
 
\t </svg> 
 
</div>

+1

它是关于尺寸和coordonates:' \t \t <圆R = “20” CX = “30” CY =“30 “class =”circle“/> \t \t \t' ,不只是它的一部分;) –

回答

2

几件事情:

  1. 内圆应该有半径5(不是10)
  2. 在你的CSS的$circumference应该是一个内圆(其半径为5),所以应该是31.4
  3. stroke-width应该是sid 10个电子(外cirlce的大小,而不是20)

这里是修复:
https://codepen.io/anon/pen/jLwjdb

注意,我也在你的js代码改变了CIRCUMFERENCE的价值,但它只影响你永远不会调用的函数onButtonClickDynamic,但它在那里以防万一你需要它。

+0

啊完美,谢谢 – Pete

+0

欢迎:) – Dekel