I'm trying to format a linear scale of a d3 chart. My y-scale are usually in the billions. I use below code:
const yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(axisLeft(y).ticks(10).tickFormat(format(".2s")))
But this gives me units in 'G' instead of 'B' when my y-axis goes into billions. See screenshot
So I replaced the last line of my code with this:
.call(axisLeft(y).ticks(10).tickFormat(format(".2s").replace("G","B")))
But I got a typeError: ×
TypeError: Object(...)(...).replace is not a function
I also tried this:
.call(axisLeft(y).ticks(10).tickFormat((d, i)=>format(".2s")(data[i].value).replace("G", "B")))
But my ticks become no longer 'nice()' and the order is all messed up.
How can I replace my unit from 'G' to 'B'? Thanks.