What I'm trying to do is create a simple donut chart. I'm currently using CSS(3) only but I don't know if it's possible without javascript.
What I have so far: http://jsfiddle.net/aBP5Q/
HTML:
<div class="donut-container" style="background: #9C0;">
<div class="donut-inner">
<div class="donut-label">HTML</div>
</div>
</div>
CSS:
.donut-container {
width: 150px;
height: 150px;
float: left;
-webkit-border-radius: 75px;
-moz-border-radius: 75px;
border-radius: 75px;
margin-right: 20px;
}
.donut-inner {
width: 134px;
height: 134px;
position: relative;
top: 8px;
left: 8px;
background: #FFF;
-webkit-border-radius: 65px;
-moz-border-radius: 65px;
border-radius: 65px;
}
.donut-label {
line-height: 130px;
text-align: center;
font-size: 20px;
}
I would like to display the green and blue colors as the precentage. So no green is 0% and full green (360 degrees) is 100%. Maybe even with a simple animation when the chart is loaded if its possible.
Your help is much appreciated.
SVG for the win!
JSFiddle version
Here is a version with background circles as requested in the comments:
How does it work?
stroke-dasharray
is used to define the 'pattern' a dashed line uses (MDN). By providing a single value you create a pattern with a dash of 440px and a space of 440px. (440px is roughly the circumference of the circle).stroke-dashoffset
effectively moves the starting point of the dash pattern (MDN).A
dash-offset
of 220 (half of thestroke-dasharray
) would produce a half-circle. 110 = quarter circle etc.