select second column of table using d3 js

Solutions on MaxInterview for select second column of table using d3 js by the best coders in the world

showing results for - "select second column of table using d3 js"
Nicolette
12 Nov 2018
1function tabulate(data, columns) {
2    var table = d3.select("body").append("table")
3            .attr("style", "margin-left: 250px"),
4        thead = table.append("thead"),
5        tbody = table.append("tbody");
6
7    // append the header row
8    thead.append("tr")
9        .selectAll("th")
10        .data(columns)
11        .enter()
12        .append("th")
13            .text(function(column) { return column; });
14
15    // create a row for each object in the data
16    var rows = tbody.selectAll("tr")
17        .data(data)
18        .enter()
19        .append("tr");
20
21    // create a cell in each row for each column
22    var cells = rows.selectAll("td")
23        .data(function(row) {
24            return columns.map(function(column) {
25                return {column: column, value: row[column]};
26            });
27        })
28        .enter()
29        .append("td")
30        .attr("style", "font-family: Courier")
31            .html(function(d) { return d.value; });
32    
33    return table;
34}
35
36// render the table
37 var peopleTable = tabulate(data, ["date", "close"]);
38