1

I have one json example below:

{"Year":2018,"Month":1,"ApplicationName":"application1","ASI":12.0,"AEI":11.0},
{"Year":2018,"Month":2,"ApplicationName":"application2","ASI":24.0,"AEI":12.0}

I want to show a ring chart with two slices:

  1. total of ASI
  2. total of AEI

How can I get crossfilter to produce the two bins for the two columns?

Gordon
  • 19,811
  • 4
  • 36
  • 74
Gurprit
  • 11
  • 1
  • 4
  • By ring graph, do you mean a pie chart with a hole in the center like the [Quarters chart on the main page](http://dc-js.github.io/dc.js/)? That's done by setting [innerRadius](http://dc-js.github.io/dc.js/docs/html/dc.pieChart.html#innerRadius__anchor). As for showing the total, you can just use [group.reduceSum()](https://github.com/crossfilter/crossfilter/wiki/API-Reference#group_reduceSum) with an accessor that adds the fields you care about. – Gordon Jul 09 '18 at 18:18
  • Thanks Gordon for reply. Will reduceSum() return total of each value ?? let say "ASI" total count and "AEI" total count. I think reduceSum() can return either "AEI" total count or "ASI" total count. Please, correct me if I am wrong. – Gurprit Jul 10 '18 at 08:11
  • Possible duplicate of [dc.js - how to create a row chart from multiple columns](https://stackoverflow.com/questions/24737277/dc-js-how-to-create-a-row-chart-from-multiple-columns) – Gordon Jul 11 '18 at 13:55
  • Hi, I came to know what I am trying to do is not possible in cross filter. My code will only create the pie chart of "ASI" and "AEI" but not filter other graphs on clicking them as the filter I am trying to apply in other graph is not valid. Some one asked to do the same as I am trying but you cleared that is not possible because I am trying to filter "ASI" and "AEI" which is not possible for other graphs to filter and it is meaning less filtering. Sharing link where i got cleared about my problem. Thanks Gordan. https://stackoverflow.com/questions/42135743/dc-js-pie-chart-combine-2-columns – Gurprit Jul 18 '18 at 08:26
  • Thanks for following up. Yes, since each row contributes to both ASI and AEI, there is no way to choose rows to filter based on these values. I don't know what your data represents, but maybe it could be put in a format which could work, maybe not. – Gordon Jul 18 '18 at 08:56

1 Answers1

0

The accessor used by reduceSum is a general function; you can put anything you want in there.

Thus,

group.reduceSum(function(d) { return d.ASI + d.AEI; });

will instruct the group to sum up all the ASIs and all the AEIs from the rows which fall into each bin.

Gordon
  • 19,811
  • 4
  • 36
  • 74
  • This will sum all d.ASI + all d.AEI right? I want each individual sum and show in pie.Modified my json ,code is below tell I am correct or not? var ASI = 0;AEI = 0;arr = []; for(var i=0; i – Gurprit Jul 10 '18 at 11:27
  • Yes it will sum all ASI and all AEI. But I'm not sure what you are trying to do with all that code. Crossfilter already does all the aggregation. If you sum everything before hand then it won't be able to filter. Please look at some crossfilter examples - there are lots out there. – Gordon Jul 10 '18 at 11:37
  • I have created js fiddle now. What I am trying to do is in my js fiddle first graph which is grouped by "ApplicationName" and reducesum by "chats" but in the second graph i have mutiple values like "ASI" and "AEI" i am unable to reducesum multiple values for that reason i have written my own function. Please check whether my code is fine or not as you are saying i would not be able to filter. Please check and correct my code there. Below is the url http://jsfiddle.net/25xtp/24/ – Gurprit Jul 11 '18 at 08:35
  • Okay, I've edited your question for clarity, and suggested a duplicate. Please let me know if this is not what you were looking for. – Gordon Jul 11 '18 at 13:54