Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
D3.js dc.js-如何将总计添加到数据表?_D3.js_Crossfilter_Dc.js - Fatal编程技术网

D3.js dc.js-如何将总计添加到数据表?

D3.js dc.js-如何将总计添加到数据表?,d3.js,crossfilter,dc.js,D3.js,Crossfilter,Dc.js,假设我在dc.js中创建了一个datatable,如下所示: ╔═══╦════════════╦═════════════╗ ║ ║ Name ║ Amount ║ ╠═══╬════════════╬═════════════╣ ║ 1 ║ Bob ║ 25 ║ ║ 2 ║ Sam ║ 25 ║ ║ 3 ║ Steve ║ 50 ║ ╚═══╩════════════╩═══

假设我在dc.js中创建了一个datatable,如下所示:

╔═══╦════════════╦═════════════╗
║   ║ Name       ║ Amount      ║
╠═══╬════════════╬═════════════╣
║ 1 ║ Bob        ║ 25          ║
║ 2 ║ Sam        ║ 25          ║
║ 3 ║ Steve      ║ 50          ║
╚═══╩════════════╩═════════════╝
如何在底部创建小计

╔═══╦════════════╦═════════════╗
║   ║ Name       ║ Amount      ║
╠═══╬════════════╬═════════════╣
║ 1 ║ Bob        ║ 25          ║
║ 2 ║ Sam        ║ 25          ║
║ 3 ║ Steve      ║ 50          ║
╚═══╩════════════╩═════════════╝
  Total is equal to 100
════════════════════════════════
任何帮助都将不胜感激

Ans:
最后,我向datatable添加了以下代码以使其正常工作

.renderlet(function (d) { return UpdateSummary(d); });

在函数“UpdateSummary”中,我更新了文本“Total等于100”

如果您共享代码,我可能可以提供更具体的帮助。这是我在此期间的建议

dc.js使用交叉过滤器组设置表的数据。无论您将哪个组设置到此表(在
.group()
方法中),请说


类似的东西。

不确定是否有效,但文档中说“数据表不使用交叉过滤组,而是使用闭包作为分组函数”。是否有任何自定义d3代码将在数据表中显示聚合数字???您是否愿意添加一个JSFIDLE来说明您的解决方案?虽然我现在就要开始我自己的工作了,但如果能有一个领先的机会就好了。谢谢
var helperArray = myGroup.all(),
total = 0;

helperArray.forEach(function(d) {total += d.value.amount;}) 
// console.log(d) to see what d is. it might need to just be total+= d.value

d3.select("body").append("p") //this should be changed to make it the right spot
    .text("Total is equal to " + total)