dc.js 每个 SKU 的平均值不正确

dc.js average value per sku not correctly

我正在使用基于 d3 和交叉过滤器的维度图表 javascript 库 dc.js 制作堆叠平均条形图。我是 dc.js 图书馆的新手..我显示了行图、饼图和数据 table.Initially 当数据加载时所有堆叠条形图平均值显示 correctly.when 我单击该行一个值的图表堆叠条形图的平均值无法正常显示。我不明白如何按照 csv 格式创建堆叠条形图。

 Sku      Stars partner review  Date
 KBU12     5       Amazon   Preferred over the r.   02/05/2016
 KBU12     5       Amazon   Gorgeous fixture    05/06/2016
 KBU12     2       Amazon   Awesome value!  02/02/2016
 KBU12      2      Homedepot    Kitchen Remodel 06/09/2016
 KPF1650    3   Homedepot   Wow 02/08/2016
 KPF1650    4   Homedepot   Sharp!  05/04/2015
 KPF1650    5   Homedepot   cool design 05/05/2015
 KPF1650    1   Amazon  Beautiful   09/08/2015
 KPF1650    2   Amazon  Very happy  09/11/2016
 GV-100     3   Amazon  Great quality   12/12/2015
 GV-100     5   Homedepot   Love it 01/03/2015
 GV-100     1   Homedepot   Sad I had to return it  12/10/2014
 GV-100     4   Homedepot   Beautiful But Stiff 12/11/2014
 GV-100     2   Homedepot   Kitchen Faucet  10/04/2014
 KBU24      3   Build       I like the look of faucet   04/05/2014
 KBU24      5   Build       Commercial style without    06/07/2016
 KBU24      4   Build       Very Cool   06/07/2014
 KBU24      1   Build       Excellent!  01/04/2014
 KBU24      3   Build       A beautiful Vessel Sink 07/06/2013
 KBU24      5   Amazon      Beautiful addition  05/04/2013

我花了一点时间才弄明白你在问什么,因为这里没有堆积条形图。

但我看到 "Review by Partners" 图表是空的,而且它使用的是平均值,所以我想这就是你问的问题。

Stars 的解析好像有误:

 d.Stars = d.Stars.match(/\d+/);

String.match 将 return 一个字符串数组。所以 reduceAdd 在尝试求和时不能直接使用它:

p.total += v.Stars;

尝试提取第一个结果并将其转换为整数:

d.Stars = +d.Stars.match(/\d+/)[0];

你的 fiddle 的工作(我认为)叉子:https://jsfiddle.net/gordonwoodhull/5xc9rh4f/1/