From cd64fb15e47a8ec1964dfb2726ff7caf34bfc161 Mon Sep 17 00:00:00 2001 From: Gordon Woodhull Date: Thu, 11 Feb 2016 13:30:36 -0500 Subject: [PATCH] add percentages to pieChart example 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 --- web/examples/pie.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web/examples/pie.html b/web/examples/pie.html index 220d7dcd8..a43e25923 100644 --- a/web/examples/pie.html +++ b/web/examples/pie.html @@ -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(); });