2016-04-25 42 views
1

我正在使用儀表板來幫助公司分析他們在多個維度上的成本。Complex Tallies/Aggregation dc.js

我有大多在工作了:https://jsfiddle.net/gkke38wk/4/

有幾件事情,我似乎無法獲得工作。 UNIQUE寶承包商

SHOW COUNT:

我已經能夠在數據表準確地顯示這是你可以在小提琴看到,但由於某些原因沒有我試穿rowChart會除了總PO的行以外,不顯示任何東西,而不是唯一PO(這是扁平的數據,每個行項目都是數據表中的一行,因此一個PO可能有很多行)例如,Bill只提交了一個PO,但它已經兩條線,圖表顯示(2)比爾)。 PO

在數據表其中大部分是工作

contractorChart 
     .dimension(contractors) 
     .group(contractorGroup) 

    contractorChart 
     .dimension(uniqueDim) 
     .group(contractorGroup) 

SHOW總額,我想總欄以顯示該PO聚合總所有行的,不只是第一場比賽。在我的uniqueDim函數中,它只能通過聚合唯一的採購訂單編號工作,而不是整個採購訂單對象。我不確定如何合計總數。

回答

2

在rowCharts中,顯示的鍵和值僅由組確定。尺寸僅用於過濾,因此切出尺寸不應導致顯示值發生任何變化。您需要讓您的小組跟蹤唯一的採購單,而不是維度。這是一個有點難以正確,高效地做,但我建議你使用Reductio exception aggregation,在這種情況下,它僅僅是一個定義歸謬法減速並在圖表上的值訪問的事情:

reductio() 
    .exception(function(d) { return d.po; }) 
    .exceptionCount(true)(contractorGroup)  

    contractorChart 
     .width(800) 
     .height(200) 
     .margins({ top: 20, left: 10, right: 10, bottom: 20 }) 
     .dimension(contractors) 
     .group(contractorGroup) 
     .ordinalColors(['#3182bd', '#6baed6', '#9ecae1', '#c6dbef', '#dadaeb']) 
     .valueAccessor(function(d) { return d.value.exceptionCount; }) 
     .label(function (d) { 
      return d.key; 
     }) 
     .title(function (d) { 
      return d.value; 
     }) 
     .elasticX(true) 
     .xAxis().ticks(4); 

至於在數據表中,您有正確的想法來創建dc.js常見問題解答中建議的「虛假維度」,但實際上您需要具有合計值的假維度。所以,它的基礎上的一組,而不是:

var uniqueDim = { 
    bottom: function (num) { 
     var pos = poDimension.top(Infinity); 
     // Uses top because the version of Crossfilter being used 
     // doesn't support group.bottom. 
     return poGroup.top(num) 
     .filter(function(d) { return d.value > 0; }) 
     .map(function(d) { 
      var currPo = pos.filter(function(g) { return g.po === d.key; })[0]; 
      return { 
      po: d.key, 
      total: d.value, 
      contractor: currPo.contractor, 
      complexity: currPo.complexity 
      }; 
     }); 
    } 
    }; 

工作兩個例子:https://jsfiddle.net/33228p1d/2/

+0

注 - 虛假維度上的過濾被破壞。現在看看:-) –

+0

問題在於group.top返回的組具有在poDimension中不存在相應記錄的0值。需要將組過濾爲具有正值的組用於假維度。 –

+0

工程太棒了!爲什麼我們使用'exceptionCount'來取代價值? – Wesley

-2

試試下面的代碼:

contractorChart 
    .width(800) 
    .height(200) 
    .margins({ top: 20, left: 10, right: 10, bottom: 20 }) 
    .dimension(contractors) 
    .group(contractorGroup) 
    .ordinalColors(['#3182bd', '#6baed6', '#9ecae1', '#c6dbef', '#dadaeb']) 
    .label(function (d) { 
     return d.key; 
    }) 
    .title(function (d) { 
     return d.value; 
    }) 
    .elasticX(true) 
    .xAxis().ticks(4); 

A小調此外,如:

contractorChart 
    .width(800) 
    .height(200) 
    .margins({ top: 20, left: 10, right: 10, bottom: 20 }) 
    .dimension(contractors) 
    .group(contractorGroup) 
    .ordinalColors(['#3182bd', '#6baed6', '#9ecae1', '#c6dbef', '#dadaeb']) 
    .label(function (d) { 
     return d.key; 
    }) 
    .title(function (d) { 
     return d.value.exceptionCount; 
    }) 
    .elasticX(true) 
    .xAxis().ticks(4); 
+0

如果你可以給你的代碼添加更多的解釋,這將是很好的。它是如何解決問題的? – Timm