Return multiple values ​​from a cross filter dimension for a pie chart

I am working with dc.js to display a pie chart. All the examples I've seen with pie charts in them contain crossfilter parameters that return a single value

var quarter = ndx.dimension(function (d) { var month = d.dd.getMonth(); if (month <= 3) return "Q1"; else if (month > 3 && month <= 5) return "Q2"; else if (month > 5 && month <= 7) return "Q3"; else return "Q4"; }); var quarterGroup = quarter.group().reduceSum(function (d) { return d.volume; }); 

The resulting pie chart will contain 4 possible values ​​of Q1, Q2, Q3 and Q4.

I need a pie chart that displays a dimension that returns multiple values. For example, a user may have an array of objects inside an attribute. In the pie chart, I need to show all possible objects, so this means that I need to return all the objects in the array.

ie Something like:

 var subjects = ndx.dimension(function (d) { return d.subjectArray }); var subjectGroup = subjects.group() 

but this will not work, as it will split the pie chart to display all types of arraists, not their contents.

I have been working on this problem for a long time and cannot find a solution. Is this possible with dc.js and crossfilter?

+4
source share
1 answer

Not an expert, but I think you need to use .reduce () in the group and create your own reduceAdd, reduceRemove and reduceInitial functions.

 .groupAll().reduce(reduceAdd, reduceRemove, reduceInitial).value(); 

As explained here , save it for a pie chart, not using barchart.

0
source

Source: https://habr.com/ru/post/1485445/


All Articles