Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
repeated y axis values with tickFormat d3

I'm getting repeated y-axis values with tickFormat d3.format('.1s'), it is like the actual number are different, like it'll be an array of [6045678, 6223456, 6076887], but when u format the numbers you'll get 6M 3 times,

what is the best solution for this problem, is there any d3 functions for this issue or do we have to create an array of values.

let yAxisValues = [6045678, 6223456, 6076887];
const yScale = d3.scaleLinear()
       .domain([d3.min(yAxisValues), d3.max(yAxisValues)])
       .range([height, 0])
       .nice();

let yAxis = d3.axisLeft(yScale)
       .tickPadding(7)
       .ticks(5)
       .tickFormat(d3.format(".1s"))
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try changing the precision number from 1 to 2/3/4 & so on in d3.format(".1s") to get what is suitable for you.

let yAxisValues = [6045678, 6223456, 6076887];
let formatter = d3.format(".1s");
let formatter2 = d3.format(".2s");
let formatter3 = d3.format(".3s");
let formatter4 = d3.format(".4s");

yAxisValues.forEach((d) => console.log(formatter(d)));
yAxisValues.forEach((d) => console.log(formatter2(d)));
yAxisValues.forEach((d) => console.log(formatter3(d)));
yAxisValues.forEach((d) => console.log(formatter4(d)));

The above code outputs as below. 6M 3 times is what you are getting, the rest is after changing the precision.

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!