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

javascript - d3.js - show large numbers on axis in abbreviated form - Stack Overflow

programmeradmin1浏览0评论

Is there a way to abbreviate large numbers on a d3.js axis? I recall seeing a helper method online but cannot find it again. I would like to abbreviate large numbers to reduce my chart margins and make it easier to read.

i.e. 1,000,000 = 1M etc

If anyone can post a link to the d3.js helper class it will be appreciated.

Is there a way to abbreviate large numbers on a d3.js axis? I recall seeing a helper method online but cannot find it again. I would like to abbreviate large numbers to reduce my chart margins and make it easier to read.

i.e. 1,000,000 = 1M etc

If anyone can post a link to the d3.js helper class it will be appreciated.

Share Improve this question asked Jul 11, 2013 at 7:55 paligappaligap 9422 gold badges13 silver badges28 bronze badges 2
  • 3 What you're looking for is 'SI prefix', and have a look at format-a-number-with-si-prefix-with-fixed-number-of-decimals and D3 formatting. – havarc Commented Jul 11, 2013 at 8:02
  • Thanks havrac for pointing me in the right direction. – paligap Commented Jul 11, 2013 at 9:04
Add a ment  | 

2 Answers 2

Reset to default 2

Check out this link https://bl.ocks/mbostock/9764126

This worked for me for d3 v4:

function make_y_gridlines() {       
        return d3.axisLeft(yScale)
               .ticks(10,"s")

}

Hi check this link: http://bl.ocks/zanarmstrong/05c1e95bf7aa16c4768e. Maybe this can help you.

For the axis you can use the following.

chart.yAxis().ticks(5).tickFormat(d3.format("s"));

I used dc.js and d3.js

Hope this can help you

发布评论

评论列表(0)

  1. 暂无评论