Abh
Abh

Reputation: 43

Showing Percentages in dc.js Row Charts

I have a pie chart that I have converted to a row chart to make it more readable.

In the label for the row chart entries, I want to be able to report on the percentage breakdown for each row (as one could with a pie chart using the start and end angles).

I'm not sure how to add the percentage to the label though. Is this possible?

Upvotes: 2

Views: 1490

Answers (1)

anmol koul
anmol koul

Reputation: 512

I think this will work. In your row chart definition just add this property

.label(function(d){
            return d.key + " : " + d.value + " - " +(d.value / ndx.groupAll().reduceCount().value() * 100).toFixed(2) + "%";
        });

This will give you something like this on the resulting horizontal bars

Active : 267 - 50.38%

You can customize this code to suit your needs.

Upvotes: 12

Related Questions