2016-07-15 76 views
1

我遇到DC.js中的表存在問題。每個奇數行都是額外的。該表應該只輸出兩列。第一列是國家,第二列是基金。但正如你在圖像中看到的那樣,有一行只顯示一個數字,在每一個偶數行的右列中都有相同的數字。DC.js表數據顯示不需要的額外行

enter image description here

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 

感謝,

+1

'showGroups'是2.0功能,它仍處於測試階段。事實上,令人討厭的是,這個功能應該如此深入。但是,該圖書館是由一個演示產生的,許多事情從未被設計爲一般。 – Gordon

回答