Skip to content

Commit

Permalink
add percentages to pieChart example
Browse files Browse the repository at this point in the history
workaround for #703

not enough data is currently available to write a `.label()`
function that displays percentages, so this demonstrates using a
pretransition hook to correct the labels
  • Loading branch information
gordonwoodhull committed Feb 11, 2016
1 parent 72fa2a7 commit cd64fb1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion web/examples/pie.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
.innerRadius(100)
.dimension(runDimension)
.group(speedSumGroup)
.legend(dc.legend());
.legend(dc.legend())
// workaround for #703: not enough data is accessible through .label() to display percentages
.on('pretransition', function(chart) {
chart.selectAll('text.pie-slice').text(function(d) {
return d.data.key + ' ' + dc.utils.printSingleValue((d.endAngle - d.startAngle) / (2*Math.PI) * 100) + '%';
})
});

chart.render();
});
Expand Down

0 comments on commit cd64fb1

Please sign in to comment.