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

227
Visualizações
How to set a time scale to a ChartJS chart from JSON?

I'm trying to code a Gantt chart using chartJS and I can't find how to do it by getting dates from json in Ajax function. Here is the code I use :

$.ajax({
url: "query.php",
method: "GET",
success: function(data) {
  for(var i in data) {
    field.push(data[i].c_nom);
    dates.push({x:data[i].c_min,x2:data[i].c_max, y: field[i]})
  }
console.log(dates);
}
});

So the logs for the line 'test4' are :

{x: '2022-04-06', x2: '2022-04-29', y: 'test4'} 

And here is what I get :

Result of datas

I don't know if I can use "x2" field because chartJS doesn't take it. So the bar is coming from 1970 I guess, and stopping at "x"...

If I put manually the dates like this - data : [['2022-04-06','2022-04-29']] , in the data instead of my array "dates", it works...

Any point in the correct direction would be most beneficial. I will also answer any queries.

Sorry if my english is not perfect.

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

0

So I found the answer by myself and it was to write the push like this :

dates.push({x:[data[i].c_min,data[i].c_max], y: field[i]})

If that may help. Thanks if you tried to help me.

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