how to draw a configurable pie chart in css

后端 未结 1 519

from the link http://www.kylejlarson.com/blog/2011/how-to-create-pie-charts-with-css3/

I am looking for a quick solution to make pie chart with css. And i don\'t know t

1条回答
  •  旧巷少年郎
    2021-01-27 06:10

    You need to change your javascript to create the divs in the appropriate places in the DOM with the appropriate rotational offsets.

    var setButti = function(n, p, f) {
            var total = n + p + f;
            var atrs = { 'tc-passed' : p*360/total, 'tc-failed' : f*360/total, 'tc-ne' : n*360/total };
            var butti = $('#buttiEl');
            butti.html('
    '); var offset = 0; for (var key in atrs) { var wedgeWidth = atrs[key]; if (wedgeWidth > 180) { $('.pieContainer', butti).append(buildWedge(key, 180, offset)); wedgeWidth -= 180; offset += 180; } $('.pieContainer', butti).append(buildWedge(key, wedgeWidth, offset)); offset += wedgeWidth * 1; } }; function buildWedge(cssClass, wedgeWidth, offset) { var wedge = $('
    '). css('-webkit-transform', 'rotate('+ wedgeWidth +'deg)'). css('-moz-transform', 'rotate('+ wedgeWidth +'deg)'). css('-o-transform', 'rotate('+ wedgeWidth+'deg)'). css('transform', 'rotate('+wedgeWidth +'deg)'); var container = $('
    '). css('-webkit-transform', 'rotate('+ offset +'deg)'). css('-moz-transform', 'rotate('+ offset +'deg)'). css('-o-transform', 'rotate('+ offset +'deg)'). css('transform', 'rotate('+offset +'deg)'); container.append(wedge); return container; }

    JS Fiddle

    0 讨论(0)
提交回复
热议问题