Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

77
Visualizações
D3 Y Axis in gap of 25 numbers

I have below D3 js code -

const svg = select(svgRef.current);
const { width, height } = wrapperRef.current.getBoundingClientRect();
const stackGenerator = stack().keys(keys);
const layers = stackGenerator(data);

const extent = [0, 100];

const yScale = scaleLinear().domain(extent).range([height, 0]);

const x0Scale = scaleBand()
  .domain(data.map((d) => d.name))
  .range([0, width])
  .padding(0.46);
const x1Scale = scaleBand()
  // .domain(data.map((d) => d.type))
  .rangeRound([0, x0Scale.bandwidth()])
  .padding(0.12);

const xAix = axisBottom(x0Scale);
const yAix = axisLeft(yScale);
svg.select(".x-axis").attr("transform", `translate(0, ${height})`).call(xAix);

svg
  .select(".y-axis")
  .attr("transform", `translate(${0 + 25}, 0 )`)
  .call(yAix);

I have extent 0 to 100 for Y Axis. I am getting Y-Axis in the group of 10 points - (0,10,20,30,40,50,60,70,80,90,100)

I want to plot it in the gap of 25 - (0,25,50,75,100)

How can I achieve it?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

when creating the y-axis you can pass the number of ticks that you want to render

svg
  .select(".y-axis")
  .attr("transform", `translate(${0 + 25}, 0 )`)
  .call(yAix.ticks(5));

the other way would be using tickValues

svg
  .select(".y-axis")
  .attr("transform", `translate(${0 + 25}, 0 )`)
  .call(yAix.tickValues([0,25,50,75,100]));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda