最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Showing Percentages in dc.js Row Charts - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question edited May 30, 2015 at 23:09 Gordon 20.2k4 gold badges39 silver badges77 bronze badges asked May 26, 2015 at 18:12 AbhAbh 434 bronze badges 1
  • This should be possible. Can you post some good and we'll see if we can figure out how to make it work? – Peter Commented May 26, 2015 at 20:16
Add a ment  | 

1 Answer 1

Reset to default 12

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.

发布评论

评论列表(0)

  1. 暂无评论