score:1
Accepted answer
If you want to treat the first column differently and make each element a th
rather than td
you could do something like the following.
var columns = ['variable', 'aror', 'asd', 'maxdd'];
var data = [
{
variable: 'Convertible Arbitrage', aror: 0.077, asd: 0.069, maxdd: -0.292,
},
{
variable: 'CTA Global', aror: 0.076, asd: 0.087, maxdd: -0.116,
},
];
var table = d3.select('body').append('table');
var thead = table.append('thead');
var tbody = table.append('tbody');
thead.append('tr')
.selectAll('th')
.data(columns)
.enter()
.append('th')
.text(function (d) { return d });
var rows = tbody.selectAll('tr')
.data(data)
.enter()
.append('tr');
var rowHeaders = rows.selectAll('th')
.data(function (row) {
return [row.variable];
})
.enter()
.append('th')
.attr('scope', 'row')
.text(function (d) { return d; });
var cells = rows.selectAll('td')
.data(function (row) {
return columns.filter(function (column) { return column !== 'variable'; }).map(function (column) {
return { column: column, value: row[column] }
})
})
.enter()
.append('td')
.text(function (d) { return d.value });
table {
width: 100%;
border: 3px solid black;
}
<script src="https://d3js.org/d3.v4.min.js"></script>
Source: stackoverflow.com
Related Query
- When creating an HTML table in D3, how can I make the first column th
- d3.js — creating HTML table from 2 dimensional array but excluding the first inner array?
- d3.js - How can I set the cursor to hand when mouseover these elements on SVG container?
- New to nvD3 - how can I make my unix timestamps appear as dates on the x-axis?
- How can I connect two parent node into one child node and how to make a tooltip for each node in the tree pragmatically? in D3 js (SVG)
- How can I use an Angularjs filter within the html element of a d3 tooltip?
- How to make grid lines when axes are aligned at the middle?
- How can I make my lines spin with the globe?
- How to make labels appear only when the chart is zoomed in
- How can I make an arc thiker than the other in D3.js
- How can I display tooltips from multiple maps when mousover on one of the maps in D3js
- D3: How to add an extra column to the table which is not in csv columns
- When creating an HTML table with D3, use certain data for a row class rather than cell
- How can I make the animation of a circle continous with hovering like this gif in d3.js?
- how can I make the shape of a medition using d3.js?
- How can I make the legend's similar to the stacked bar chart (and change the legend's label) in D3 v6?
- Make a specific column bold in an html table
- How Can I highlight the parents names and the connection lines when I hover on their child in family tree
- D3.js: How can I put an image on the background of a circle with the remaining parts trimmed and make it resize along with the circle onclick?
- How to make the cursor change in d3.js when I want?
- How to put first row in tsv to row thead <th> in table and the rest go to tbody <td> with d3
- How can i show the labels on the x axis when there is data overlap in d3js?
- How to start D3 JS Tree to render in Collapsible Mode when loaded for the first time
- How can I make a bar chart starting from the 0 point of the y axis and not from the bottom of the svg?
- D3 Tree: How to make children checked and disabled recursively when the parent node is checked
- How can I make both HTTP and Websocket requests at the same time on the same server?
- How can I properly aggregate / group multiple line graphs into one overall graph with d3.js when the x-values aren't matching exactly?
- D3 - How can I show/hide a text element when hovering a circle element created from different attributes of the same data entry?
- How can i make count to be displayed permanently at the end of graph bars?
- How can I use the following html to dynamically create wordclouds for my android app?
More Query from same tag
- Set a minimum height on bars in D3 graph
- d3.js donut chart with legend outside donut
- Troubles with bootstrap modal with angular
- Metricsgraphics Date access - Line graph
- nvd3.js: pie chart tooltips blinking in IE 10
- d3 x axis not starting at 00:00 but instead at 02:00
- Why do I need a 00 time zone offset to display values correctly in d3v4?
- d3: Adding the min/max/mean lines to an existing linechart
- How do I catch xlink:href errors in D3?
- Extending Bokeh to match D3.js
- Fix SVG element while scrolling vertically, issues with Firefox
- X3DOM ImageTexture in a bl.ocks.org and animate it using d3.js
- D3 circle object has no properties
- D3 - format elapsed time
- Count text fields from csv dataset in d3 js
- MNaN and NaN coordinates on a d3.js streamgraph
- Return values from a map
- How to avoid .lower() to reshuffle elements in d3?
- Trying to do a dynamic radius in d3.js and getting error: TypeError: size is not a function
- Redux Store updated, but isn't reflected in mapStateToProps
- Embellishing D3 SVG circle pack diagram
- D3.JS Vertical line separating year
- D3 drag & click in v6 for grouped objects
- How to customize d3plus large tooltip
- csv filsize limit when importing with d3.csv
- Uncaught TypeError: d3plus.Pie is not a constructor
- How to Make True Zero Duration Instant Transitions in D3
- Rects won't show up on d3 histogram
- How to define the color of strokes
- Center SVG <tspan> elements when surrounding <text> element has text-anchor=start