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

191
Visualizações
How to format axis text containing month value in D3

I am trying to plot a graph using D3 and react. The sample data I been using is of this format

[{
    "date": "01-01-2022",
    "site": "Site 1",
    "type": "circle"
},
{
    "date": "01-01-2022",
    "site": "Site 4",
    "type": "square"
}
...
]

The xScale and yScale are declared as

 const xValue = (d) => d.date;
 const xScale = scaleTime()
    .domain(extent(data, xValue))
    .range([0, innerWidth]);

const yValue = (d) => d.site;
const yScale = scaleThreshold()
.domain(data.map((d) => yValue(d)))
.range([
  "Site 1",
  "Site 2",
  "Site 3",
  "Site 4",
  "Site 5",
  "Site 6",
  "Site 7",
  "Site 8",
  "Site 9"
]);

And the x axis component AxisBottom is with tickFormat is defined as const xAxisTickFormat = timeFormat("%B");

export const AxisBottom = ({
  xScale,
  innerHeight,
  tickFormat,
  tickOffset = 3
}) => {
  return xScale.ticks().map((date) => (
    <g
      className="tick"
      key={date}
      transform={`translate(${xScale(date)}, ${0})`}
    >
        <text
            y={innerHeight + tickOffset}
            dy=".7em"
            style={{ textAnchor: "middle" }}
       >
       {tickFormat(date)}
       </text>
    </g>
  ));
};

What I'm trying to achieve is for all data points for a month, say January display January once as text in the x-axis. The work so far has been compiled in codesandbox. Any suggestions would be really helpful.

about 4 years ago · Juan Pablo Isaza
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