When I use the code shown this dc.js doc
https://github.com/dc-js/dc.js/blob/master/web/docs/api-1.7.0.md#labellabelfunction
I get a different answer. Is the documentation wrong? For instance, when I use the trick to dump the data structure to the console:
.label(function(d){
console.log(JSON.stringify(d));
return d.key;
)};
I get:
{"key":"M16SDH","value":690}
{"key":"M16SP","value":886}
{"key":"M16SPS","value":704}
There is no "d.data" object, and therefore trying to compute the percentage this way does not work:
// Simple pie chart to filter on type.
var byTypeChart = dc.pieChart("#byTypeDiv");
var byTypeDim = ndx.dimension(function (d) { return (d.celltype == null?'na':d.celltype); });
var byTypeGroup = byTypeDim.group();
byTypeChart
.width(200).height(200)
.dimension(byTypeDim)
.group(byTypeGroup)
.label(function(d){
return d.data.key + "(" + Math.floor(d.data.value / all.value() * 100) + "%)";
})
;
The document says:
// label function has access to the standard d3 data binding and can get quite complicated
but I see:
TypeError: d.data is undefined
.dataright? - Gordon