我在DC.js中遇到问题。每个奇数行都是额外的。该表应该只输出两列。第一列是州,第二列是称为基金的金额。但正如您在图像中看到的那样,有一个额外的行只显示一个数字,相同的数字位于每个偶数行的右列中。
JS代码,
<script>
var text = '[';
var obj;
url = "/funding";
d3.json(url, function(error, json_response) {
for (var item in json_response['proposals']) {
item = parseInt(item);
fund = json_response['proposals'][item]['totalPrice'];
state = json_response['proposals'][item]['state'];
obj = '{ "state":' + '"' + state + '"' + ', "fund":' + fund + '}';
text += obj + ',';
}
text = text.substring(0, text.length - 1);
text += ']';
data = JSON.parse(text);
cf = crossfilter(data);
stateDim = cf.dimension(function(d) {
return d.state;
});
fundDim = stateDim.group().reduceSum(function(d) {
return d.fund;
});
datatable = dc.dataTable("#tablechart");
datatable
.dimension(stateDim)
.group(function(d) {
return d.fund;
})
.columns([
function(d) {
return d.state;
},
function(d) {
return d.fund;
}
]);
dc.renderAll();
});
</script>
html,
<div class="table-responsive">
<table id="tablechart" class="table table-bordered table-hover table-striped">
<thead>
<tr class="header">
<th>State</th>
<th>Funding($)</th>
</tr>
</thead>
</table>
</div>
我尝试添加,(我从here获得)
.showGroups(false)
但是我进入了控制台,
Uncaught TypeError: datatable.dimension(...).group(...).showGroups is not a function
(anonymous function) @ (index):388
(anonymous function) @ d3.min.js:1
t @ d3.min.js:1
i @ d3.min.js:1
谢谢,
答案 0 :(得分:1)