I have a dataset similar to below:
I would like to find total amount of "sea shipment" over "train shipment" and display it with dc.numberDisplay("#");
total sea shipment / total train shipment
Not sure if i need to use custom reduction.
so far i have used below code but it returns 1
ndx = crossfilter(data);
var all = ndx.groupAll();
var allGroup = all.reduce(
function (p, v) {
p.total += v.total;
p.sea = (v.shipment_type === "sea") ? 0 : p.total ;
p.train = (v.shipment_type === "train") ? 0 : p.total ;
p.air = (v.shipment_type === "air") ?0 : p.total ;
p.sea_over_train = p.sea / p.train;
return p;
},
function (p, v) {
p.total -= v.total;
p.sea = (v.shipment_type === "sea") ? 0 : p.total ;
p.train = (v.shipment_type === "train") ? 0 : p.total ;
p.air = (v.shipment_type === "air") ?0 : p.total ;
p.sea_over_train = p.sea / p.train;
return p;
},
function () {
return {
total: 0,
sea: 0,
train :0,
air:0,
sea_over_train:0,
};
}
);
seaOverTrain
.group(allGroup)
.valueAccessor(function (x) { return x.sea_over_train; })
.formatNumber(d3.format(".3s"));
