I would like to make further calculations from the values of two separate numberDisplays in dc.js
Here's the code,
function makeGraphs(data) {
xf = crossfilter(data);
all = xf.groupAll();
txntypeDim = xf.dimension(function(d) { return d.txntype; });
sumAllTXN = txntypeDim.groupAll().reduceSum(function(d) {return d.txnamount;});
numberRecordsND = dc.numberDisplay("#number-records-nd",groupname)
numberRecordsTXN = dc.numberDisplay("#number-records-txn",groupname)
numberRecordsND
.formatNumber(d3.format("d"))
.valueAccessor(function(d){return d; })
.group(all);
numberRecordsTXN
.formatNumber(function(d){return d; })
.valueAccessor( function(d) { return d; } )
.group(sumAllTXN);
dc.renderAll(groupname);
}
I want to show the percentage of numberRecordsTXN/numberRecordsND in another div. Is there any way to achieve this?
Edit: solution code;
function makeGraphs(data) {
xf = crossfilter(data);
all = xf.groupAll();
txntypeDim = xf.dimension(function(d) { return d.txntype; });
sumAllTXN = txntypeDim.groupAll().reduceSum(function(d) {return d.txnamount;});
numberRecordsND = dc.numberDisplay("#number-records-nd",groupname)
numberRecordsTXN = dc.numberDisplay("#number-records-txn",groupname)
numberRecordsAVG = dc.numberDisplay("#number-records-avg",groupname)
numberRecordsND
.formatNumber(d3.format("d"))
.valueAccessor(function(d){return d; })
.group(all);
numberRecordsTXN
.formatNumber(function(d){return d; })
.valueAccessor( function(d) { return d; } )
.group(sumAllTXN);
numberRecordsAVG
.formatNumber(d3.format("d"))
.valueAccessor(function(d){return d; })
.group(groupall_percent(numberRecordsTXN, numberRecordsND));
dc.renderAll(groupname);
};
function groupall_percent(numerator, denominator) {
return {
value: function() {
return numerator.value() / denominator.value();
}
};
};