Friday, May 20, 2011

Wedge


<html>
    <head>
    <script type="text/javascript"  src="protovis-r3.2.js"></script>
    </head>
    <body>
    <script type="text/javascript+protovis"
    var w = 150,
        h = 150,
        l = 75,
        b = 75;
    var data = [222], sum = pv.sum(data);
    var colors = ["red""yellow""green"];
    
    function calculateangle(data, idx)
    {
        var sum = pv.sum(data);
        
        if(idx > 0)
        {
            var hasil = 0;
            for(i=0; i<idx; i++) hasil+=data[i];
            return Math.PI + (hasil / sum * Math.PI);
        }
        else
        {
            return Math.PI;
        }
    }
    
    new pv.Panel()
        .width(w)
        .height(h)
        .add(pv.Wedge)
        .data(data)
        .left(l)
        .bottom(b)
        .innerRadius(30)
        .outerRadius(70)
        .startAngle(function(d) calculateangle(data, this.index))
        .angle(function(d) (d / sum * Math.PI))
        .fillStyle(function() colors[this.index])
        .root.render();
    </script>
    </body>
</html>

No comments:

Post a Comment