D3.js v4 prepare an object for a Pie Chart

Prepare an array object for a pie chart using d3.pie()(data).value().

   var = data_count = [{
        key: "f",
        value: 2
      },
      {
        key: "m",
        value: 1
      }
    ]

    var arcs = d3.pie()
      .value(function(d) {
        return d.value;
      })
      (data_count);

    arcs.forEach(function(element) {
      console.log(element);
    });

This will generate the array object,

arcs = [
{index: 0, value: 2, startAngle: 0, endAngle: 4.1887902047863905, padAngle: 0},
{index: 1, value: 1, startAngle: 4.1887902047863905, endAngle: 6.283185307179586, padAngle: 0}
]

D3.js v4 prepare array for a Pie Chart

Use d3.pie()(data) to prepare an array of numbers for a pie chart.

var data = [1, 1, 2, 3, 5, 8, 13, 21];
    var arcs = d3.pie()(data);

    arcs.forEach(function(element) {
      console.log(element);
    });

This will generate a new array object,

arcs = [
{data: 1, index: 6, value: 1, startAngle: 6.050474740247008, endAngle: 6.166830023713296, padAngle: 0},
{data: 1, index: 7, value: 1, startAngle: 6.166830023713296, endAngle: 6.2831853071795845, padAngle: 0},
{data: 2, index: 5, value: 2, startAngle: 5.817764173314431, endAngle: 6.050474740247008, padAngle: 0},
{data: 3, index: 4, value: 3, startAngle: 5.468698322915565, endAngle: 5.817764173314431, padAngle: 0},
{data: 5, index: 3, value: 5, startAngle: 4.886921905584122, endAngle: 5.468698322915565, padAngle: 0},
{data: 8, index: 2, value: 8, startAngle: 3.9560796378538132, endAngle: 4.886921905584122, padAngle: 0},
{data: 13, index: 1, value: 13, startAngle: 2.443460952792061, endAngle: 3.9560796378538132, padAngle: 0},
{data: 21, index: 0, value: 21, startAngle: 0, endAngle: 2.443460952792061, padAngle: 0}
]