Accepted answer

Please note that data is an array of objects and not an object. So to get the keys of an object, you should apply d3.keys function on one of the objects in the array. Like this -

tabulate(data, d3.keys(data[0])); //data[0] is an object, applying d3.keys(data[0]) will return [Label, Count]

var data = [{
    "Label": "External-Partner-Induced",
    "Count": 9
    "Label": "Null",
    "Count": 1
    "Label": "FCTS-Induced",
    "Count": 66
    "Label": "EI-Partner-Induced",
    "Count": 78

function tabulate(data, columns) {
  var table ='body').append('table')
  var thead = table.append('thead')
  var tbody = table.append('tbody');

  // append the header row
    .text(function(column) {
      return column;

  // create a row for each object in the data
  var rows = tbody.selectAll('tr')

  // create a cell in each row for each column
  var cells = rows.selectAll('td')
    .data(function(row) {
      return {
        return {
          column: column,
          value: row[column]
    .text(function(d) {
      return d.value;
  return table;
// render the table
tabulate(data, d3.keys(data[0]));
<script src=""></script>

Related Query

More Query from same tag