Reputation: 83
Dimension 'dim_pie' is passing any character value and Measure 'fact_pie' is passing any integer type value.
So how can i display the percentage of Measure value on label of pie-chart and how can i partition all pie slice based on sum of measure value ?
var ndx = crossfilter(datachart);
var dim_pie = ndx.dimension(function(d) {return d.Opportunity_Name;});
var fact_pie = dim_pie.group().reduceSum(function(d) {return +d.Amount;});
PieChart
.width(300)
.height(400)
.dimension(dim_pie)
.group(fact_pie)
.innerRadius(30)
.renderLabel(true)
.label(function(d){ return d.key + " : " + d.value + " - " +(d.value / ndx.groupAll().reduceCount().value() * 100).toFixed(2) + "%"; })
.colors(d3.scale.ordinal().range([ "red", "#006400" ]))
;
Data: Opportunity_Name Amount Accenture 10 Apple 80 Cognizant 80 CTS 20 Dell 60 Facebook 40 Google 20 Hp 20 Hp 10 IBM 30 LinkedIn 10 Oracle 90 TCS 10 Wipro 80 Wipro 10
Upvotes: 0
Views: 999
Reputation: 512
Please add this code to your pie chart.
.label(function(d) { return d.key +" (" + Math.floor(d.value / all.value() * 100) + "%)"; });
This will display percentages of your measure values in brackets along with the key name.
Upvotes: 1