dc.js boxplot b.map(...).sort is not a function

I am trying to generate box plot. After creating dimension and group I've followed the example given at https://github.com/dc-js/dc.js/blob/master/web/examples/box-plot.html

I'm using reductio to make the reductions easier:

var ndx = crossfilter(ds);
var skuDim = ndx.dimension(function(d){ return d.sku; });
var skuGroup = skuDim.group();

var reducer = reductio();
reducer
  .value('_nc')
  .sum(function(d){
      return d.nc;
  });
reducer
  .value('_ta')
  .sum(function(d){
      return d.ta;
  });

reducer(skuGroup);

I'm also using a valueAccessor for my group:

  .valueAccessor(function(p){
    return p.value._nc.sum ? Math.round(p.value._ta.sum / p.value._nc.sum * 100) / 100 : 0;
  })

I'm getting this error:

TypeError: b.map(...).sort is not a function.

I've added a fiddle to replicate this issue. https://jsfiddle.net/momhzyxp/7/

Cheers


Instead of using reductio to aggregate the values into sums, you can use reductio.dataList to produce arrays of the original rows that fall into each bin:

var reducer = reductio();
reducer
  .value('_rows')
  .dataList(true);

reducer(skuGroup);

Then, assuming you want to divide each ta by each nc (not sure what you are trying to do here), the valueAccessor looks like:

  .valueAccessor(function(p){
    var values = p.value._rows.dataList.map(function(v, i) {
      return v.nc ? Math.round(v.ta / v.nc * 100) / 100 : 0;
    });
    return values;
  })

(or you can do whatever you like with each v.ta and v.nc ).

Fork of your fiddle: https://jsfiddle.net/oawbzdgy/11/

链接地址: http://www.djcxy.com/p/32806.html

上一篇: 从交叉过滤器中提取一列

下一篇: dc.js boxplot b.map(...)。sort不是一个函数