Rashmit Dalbir Singh Rashmit Dalbir Singh - 6 months ago 116
Javascript Question

D3: Formatting tick value. To show B (Billion) instead of G (Giga)

I want to format Y-axis data in D3 Line chart. It's about world population so that is quite large.

I am currently using below code, which is showing "G" instead of "B".


I researched and found that here "G" stands of Giga, is there a way to change it to B which denotes Billion?



If you like the formatting of SI-prefix, but not the actual prefix, just swap it out with a simple .replace:

var f = d3.format("0.2s");

<script src="https://d3js.org/d3.v4.min.js"></script>