plotly.js

The open source JavaScript graphing library that powers Plotly

Show Sidebar Hide Sidebar
Plotly.js

Tables in plotly.js

How to make a D3.js-based tables in javascript.

var values = [
      ['Salaries', 'Office', 'Merchandise', 'Legal', 'TOTAL'],
      [1200000, 20000, 80000, 2000, 12120000],
      [1300000, 20000, 70000, 2000, 130902000],
      [1300000, 20000, 120000, 2000, 131222000],
      [1400000, 20000, 90000, 2000, 14102000]]

var data = [{
  type: 'table',
  header: {
    values: [["EXPENSES"], ["Q1"],
				 ["Q2"], ["Q3"], ["Q4"]],
    align: "center",
    line: {width: 1, color: 'black'},
    fill: {color: "grey"},
    font: {family: "Arial", size: 12, color: "white"}
  },
  cells: {
    values: values,
    align: "center",
    line: {color: "black", width: 1},
    font: {family: "Arial", size: 11, color: ["black"]}
  }
}]

Plotly.plot('graph', data);
var values = [
      ['Salaries', 'Office', 'Merchandise', 'Legal', 'TOTAL'],
      [1200000, 20000, 80000, 2000, 12120000],
      [1300000, 20000, 70000, 2000, 130902000],
      [1300000, 20000, 120000, 2000, 131222000],
      [1400000, 20000, 90000, 2000, 14102000]]

var data = [{
  type: 'table',
  header: {
    values: [["EXPENSES"], ["Q1"],
				 ["Q2"], ["Q3"], ["Q4"]],
    align: ["left", "center"],
    line: {width: 1, color: '#506784'},
    fill: {color: '#119DFF'},
    font: {family: "Arial", size: 12, color: "white"}
  },
  cells: {
    values: values,
    align: ["left", "center"],
    line: {color: "#506784", width: 1},
	 fill: {color: ['#25FEFD', 'white']},
    font: {family: "Arial", size: 11, color: ["#506784"]}
  }
}]

Plotly.plot('graph', data);
Plotly.d3.csv("https://raw.githubusercontent.com/plotly/datasets/master/Mining-BTC-180.csv", function(err, rows){

  function unpack(rows, key) {
  return rows.map(function(row) { return row[key]; });
  }

  var headerNames = Plotly.d3.keys(rows[0]);

  var headerValues = [];
  var cellValues = [];
  for (i = 0; i < headerNames.length; i++) {
    headerValue = [headerNames[i]];
    headerValues[i] = headerValue;
    cellValue = unpack(rows, headerNames[i]);
    cellValues[i] = cellValue;
  }

  // clean date
  for (i = 0; i < cellValues[1].length; i++) {
  var dateValue = cellValues[1][i].split(' ')[0]
  cellValues[1][i] = dateValue
  }


var data = [{
  type: 'table',
  columnwidth: [200,500,600,600,400,400,600,600,600],
  columnorder: [0,1,2,3,4,5,6,7,8,9],
  header: {
    values: headerValues,
    align: "center",
    line: {width: 1, color: 'rgb(50, 50, 50)'},
    fill: {color: ['rgb(235, 100, 230)']},
    font: {family: "Arial", size: 11, color: "white"}
  },
  cells: {
    values: cellValues,
    align: ["center", "center"],
    line: {color: "black", width: 1},
    fill: {color: ['rgba(228, 222, 249, 0.65)','rgb(235, 193, 238)', 'rgba(228, 222, 249, 0.65)']},
    font: {family: "Arial", size: 10, color: ["black"]}
  }
}]

var layout = {
  title: "Bitcoin mining stats for 180 days"
}

Plotly.plot('graph', data, layout);
});
var values = [
      ['Salaries', 'Office', 'Merchandise', 'Legal', 'TOTAL
EXPENSES
'], ["Lorem ipsum dolor sit amet, tollit discere inermis pri ut. Eos ea iusto timeam, an prima laboramus vim. Id usu aeterno adversarium, summo mollis timeam vel ad", "Lorem ipsum dolor sit amet, tollit discere inermis pri ut. Eos ea iusto timeam, an prima laboramus vim. Id usu aeterno adversarium, summo mollis timeam vel ad", "Lorem ipsum dolor sit amet, tollit discere inermis pri ut. Eos ea iusto timeam, an prima laboramus vim. Id usu aeterno adversarium, summo mollis timeam vel ad", "Lorem ipsum dolor sit amet, tollit discere inermis pri ut. Eos ea iusto timeam, an prima laboramus vim. Id usu aeterno adversarium, summo mollis timeam vel ad", "Lorem ipsum dolor sit amet, tollit discere inermis pri ut. Eos ea iusto timeam, an prima laboramus vim. Id usu aeterno adversarium, summo mollis timeam vel ad"]] var data = [{ type: 'table', columnorder: [1,2], columnwidth: [80,400], header: { values: [["EXPENSES
as of July 2017"], ["DESCRIPTION"]], align: ["left", "center"], height: 40, line: {width: 1, color: '#506784'}, fill: {color: '#119DFF'}, font: {family: "Arial", size: 12, color: "white"} }, cells: { values: values, align: ["left", "center"], height: 30, line: {color: "#506784", width: 1}, fill: {color: ['#25FEFD', 'white']}, font: {family: "Arial", size: 11, color: ["#506784"]} } }] Plotly.plot('graph', data);
var values = [
      ['Salaries', 'Office', 'Merchandise', 'Legal', 'TOTAL'],
      [1200000, 20000, 80000, 2000, 12120000],
      [1300000, 20000, 70000, 2000, 130902000],
      [1300000, 20000, 120000, 2000, 131222000],
      [1400000, 20000, 90000, 2000, 14102000]]

var headerColor = "grey";
var rowEvenColor = "lightgrey";
var rowOddColor = "white";

var data = [{
  type: 'table',
  header: {
    values: [["EXPENSES"], ["Q1"],
				 ["Q2"], ["Q3"], ["Q4"]],
    align: "center",
    line: {width: 1, color: 'black'},
    fill: {color: headerColor},
    font: {family: "Arial", size: 12, color: "white"}
  },
  cells: {
    values: values,
    align: "center",
    line: {color: "black", width: 1},
    fill: {color: [[rowOddColor,rowEvenColor,rowOddColor,
						  rowEvenColor,rowOddColor]]},
    font: {family: "Arial", size: 11, color: ["black"]}
  }
}]

Plotly.plot('graph', data);

Please see Table Subplots documentation.

Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.