js每sku的平均值不正确

dc.js average value per sku not correctly

本文关键字:平均值 不正确 sku js      更新时间:2023-09-26

我正在使用多维图表javascript库dc.js制作堆叠平均条形图,这是基于d3和交叉过滤器。我是新的dc.js库..我已经显示行图,饼图和数据表。最初,当数据加载时,所有堆叠的条形图平均值正确显示。当我点击一个值的行图时,堆叠条形图的平均值无法正常显示。我不明白如何按照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

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

但是我看到"合伙人评论"的图表是空的,它使用的是平均值,所以我想这就是你要问的。

看起来星号的解析是不正确的:

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

字符串。Match将返回一个字符串数组。所以当reduceAdd试图求和时不能直接处理这个

p.total += v.Stars;

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

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

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