Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!