score:5

you'll need to build custom grouping/reduce functions to track the count of each status as well as the total count. then you can just divide in the chart to calculate your percentage. if you are interested in using reductio, you can probably do the following:

``````var reducer = reductio().count(true);

// do this as many times as you need for different status counts. each
// call of reducer.value will add a new property to your groups where
// you can store the count for that status.
reducer.value("screenfailure").sum(
function(d) {
// this counts records with subjectstatus = "screen failure"
return d["subjectstatus"] === "screen failure" ? 1 : 0;
});

// build the group with the reductio reducers.
var numsubjectsbysite = reducer(sitename.group());

// in your dc.js chart, calculate the % using a value accessor.
sitelevelchart
.width(2000)
.height(200)
.transitionduration(1000)
.dimension(sitename)
.group(numsubjectsbysite)
.valueaccessor(function(p) { return p.value.screenfailure.sum / p.value.count; })
.ordering(function(d){return d.value;})
``````

score:3

you can use a custom groupall for this. here is a straight crossfilter solution, based on the jsfiddle you provided in a later question.

(it's a lot easier to answer with a fiddle to work with!)

``````var all = ndx.groupall();
var failurepercentgroup = all.reduce(
function(p, v) {
++p.count;
p.failures += (v.status === 'screen failure' ? 1 : 0);
p.failpercent = p.count ? p.failures/p.count : 0;
return p;
},
function(p, v) {
--p.count;
p.failures -= (v.status === 'screen failure' ? 1 : 0);
p.failpercent = p.count ? p.failures/p.count : 0;
return p;
},
function() {
return {
count: 0,
failures: 0,
failpercent: 0
};
}
);

failurepercent.valueaccessor(function (x) {
return x.failpercent;
})
.group(failurepercentgroup);
``````

@ethan's answer looks like it should work, but you remarked elsewhere that you couldn't get it to work.

updated fiddle here: http://jsfiddle.net/gordonwoodhull/vct0dzou/8/

i didn't deal with formatting it as a percent, so it just shows a ratio, but you should be able to figure that part out.