0

I tried setting a linear range and domain to convert it, but that doesn't seem to work. I just need to create a completion chart. 50,000 being 100% and a current value of (lets say 25,000). How do I convert my normal values to radians?

Here's what I have so far:

var pieScale = d3.scale.linear().range([0, 8]);
    pieScale.domain([0, 50000]);

    var svg = d3.select("#redCircle").append("svg")
                .attr({
                    'preserveAspectRatio': 'xMinYMin meet'
                });


    var marginArc = d3.svg.arc()
                        .startAngle(0)
                        .innerRadius(0)
                        .outerRadius(100);

    var marginArcSvg = svg.append("path")
                            .attr({
                                "d": function (d) {
                                    marginArc.endAngle((2 * Math.PI) * pieScale(25000));
                                    return marginArc();
                                },
                                "transform": function (d) {
                                    return "translate(" + 100 + ", " + 100 + ")"
                                },
                                "fill": "white"
                            });
Brandon
  • 3,074
  • 3
  • 27
  • 44

1 Answers1

2

Current value divided by 50,000 gives you the percentage around the circle. Then convert that to radians with the following pseudo-code

var radians = percentage * 2 * Math.PI

Source: HTML5: Fill circle/arc by percentage

Community
  • 1
  • 1
Feathercrown
  • 2,547
  • 1
  • 16
  • 30