当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Alternative for reduceSum in crossfilter and dc

问题描述:

I have a dataset of the following kind:

a:5 b:4 c:3 d:A

a:6 b:5 c:4 d:A

a:7 b:6 c:5 d:B

a:8 b:7 c:6 d:B

a:9 b:8 c:7 d:C

I wanted 'd' to be the dimension for my crossfilter and the value to be plotted in the graph is (a/b) from the dataset. For doing this, I added an extra field in my dataset called 'e'=(a/b) and then passed it as an i/p to crossfilter in the following way:

var facts = crossfilter(json); // json being the name of my dataset

var pfmValue = facts.dimension(function(d) {return d.d;});

var pfmValueGroupSum = pfmValue.group().reduceSum(function(d) {return +d.e;});

Then I plotted a dc chart using pfmValue as dimension and pfmValueGroupSum along the Y-axis of the bar chart.But now I realise that this is not what I wanted to plot.Now, i have three bars showing values equal to following expression:

bar A: (5/4)+(6/5)

bar B: (7/6)+(8/7)

bar C: (9/8)

However what I wanted is:

bar A: (5+6)/(4+5)

bar B: (7+8)/(6+7)

bar C: (9/8)

How do I do it??Any suggestions will be appreciated.

网友答案:

You probably need to create a custom grouping that tracks the sum of "a" and the sum of "b" in separate properties. Then you can figure "sum a"/"sum b" when you build your visualization.

分享给朋友:
您可能感兴趣的文章:
随机阅读: