【发布时间】:2020-09-24 15:21:48
【问题描述】:
我正在使用以下代码将表格添加到我的 d3 图表中。
function tabulate(data, columns) {
const table = d3.select('body').append('table')
const thead = table.append('thead')
const tbody = table.append('tbody');
// append the header row
thead.append('td')
.selectAll('th')
.data(columns).enter()
.append('th')
.text((column) => column);
// // create a row for each object in the data
const rows = tbody.selectAll('tr')
.data(data)
.enter()
.append('tr');
// create a cell in each row for each column
const cells = rows.selectAll('td')
.data((row) => {
return columns.map((column) => {
return { column: [column], value: row[column] };
});
})
.enter()
.append('td')
.text((d) => d.value);
return table;
}
我需要在表格中添加一个垂直标题,并将 json 对象中的每个键读取到单行中的多个列中。如何在 d3 中实现这一点?请帮忙。
【问题讨论】:
-
你能告诉我们你的
data对象吗? -
下面是我的 json 数据模型:export interface ZRTData { A: string; B:号码; C:号码; D_percentage:数字;我需要在 d3 图表下添加带有标题 D_percentage 和 JSON 值的单行。我需要添加一个垂直标题和单行,其中包含来自 json 的具有不同 D_percentage 值的多列。
标签: javascript html css angular d3.js