Took it seriously, so answering with bit delay.
First, possibly something like this could be done better using canvas drawing (need check it), but just for fun made crazy mix with LESS+HTML+CSS3 and bit JavaScript which seems work anyway.
Here is working example https://c9.io/dmi3y/css3pie/workspace/index.html
Should works with all modern browsers, and IE9 +, possibly you could add support to IE versions lower than 9. For this needed support for border radius and transforms. Latter one could be done with Matrix filter, and here is something to read plus working solution in .htc file http://samuli.hakoniemi.net/cross-browser-rotation-transformation-with-css/, but I do not tested it and personally would not care about older browsers much. I would just add notice about if you want see something upgrade browser. Also in FireFox there is some artefacts, possibly because I am using pseudo classes ::before
and ::after
and may be using real elements will improve this.
Tech information. Here is 9cloud code https://c9.io/dmi3y/css3pie. The core idea is using dynamically generated CSS using client side LESS. So with bit jQuery code which is taken for convenience and easily could be converted to any other library/core js.
Mile stones:
in your markup you define how many area should be filled in degrees
<div class="circle" id="pieOne" data-fill="30deg"></div>
and basically to make it works this is everything you need.
This is brief explanation what's going on:
Taking this value I do override LESS variables in embed styles and create CSS with less.refreshStyles()
<style type="text/less" id="lessPie">
@import 'styles/pie';
@fillDegree: #dataDegree#; // from 0deg to 180deg
@baseRotate: 40deg;
</style>
<script type="text/javascript">
!function(){
var lessPieText = $('#lessPie').text();
$(function(){
var pieOneDataFill = $('#pieOne').attr('data-fill');
while (parseInt(pieOneDataFill) > 180) {
pieOneDataFill = (parseInt(pieOneDataFill) - 180) + 'deg';
}
while (parseInt(pieOneDataFill) < 0) {
pieOneDataFill = (parseInt(pieOneDataFill) + 180) + 'deg';
}
$('#lessPie').text(lessPieText.replace('#dataDegree#', pieOneDataFill));
less.refreshStyles();
// update % value
// 180deg = 100%
// pieOneDataFill = x%
var percentValue = (parseInt(pieOneDataFill) * 100) / 180;
$('#pieOneLegend').find('span').text(Math.floor(percentValue) + '%').end().show();
});
}()
</script>
As additional bonus you may rotate pie with @baseRotate: 40deg;
value. Also shown legend with % value.
That's pretty much everything. For a while it support only one pie per page (or rather one type of pie) with one value. I will push this on github later and probably will work on project as it sounds to become interesting.