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

134
Visualizações
D3 Trouble Altering Date

I'm importing a csv file and d3 treats every column as a string. The dates are currently stored like so: 2016-11-01. I'm trying to alter this column so that it will appear as Nov 16 (abbreviated month, abbreviated year).

Here is the code I have so far:

var dateParse = d3.timeParse("%Y-%m-%d") //matches the format in the csv
var monthParse = d3.timeParse("%m %y") //the format I'm looking for

var rowConverter = function (d) {
     return {
          date: dateParse(d.date)
          month: monthParse (d.date) //also tried monthParse(date)
     };
}

d3.dsv(",","my_csv.csv", rowConverter)

I expected this to give me two columns: one that would be the full date and one with the abbreviated month and year. I've confirmed the dateParse works correctly using console.log() statements. The monthParse, however, just results in NaNs. How can I get this column to populate correctly?

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

0

d3.timeParse converts a string to a Date object. d3.timeFormat converts a Date object to a string.

You might be looking for something like this:

const dateParse = d3.timeParse("%Y-%m-%d");
const dateFormat = d3.timeFormat("%m %y");

function rowConverter(d) {
  const date = dateParse(d.date);
  return {
    date: date,
    month: dateFormat(date)
  };
}
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