EG of Using d3.nest()

by Nivaldo

JavaScript

var seatsPaxAirline = 
    [{key: "5Y", value: {pax: 60, seats: 100}},
     {key: "5Y", value: {pax: 40, seats: 100}},
     {key: "3Y", value: {pax: 30, seats: 100}},
     {key: "2Y", value: {pax: 70, seats: 100}},
     {key: "4Y", value: {pax: 50, seats: 100}},
     {key: "1Y", value: {pax: 45, seats: 100}},
     {key: "2Y", value: {pax: 50, seats: 100}},
     {key: "5Y", value: {pax: 60, seats: 100}},
     {key: "5Y", value: {pax: 65, seats: 100}},
     {key: "5Y", value: {pax: 55, seats: 100}}
     ];

var output = d3.nest().key(function(d){return d.key}).map(seatsPaxAirline);
d3.select("body").html(JSON.stringify(output));
console.log(output);