Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda