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 :
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.
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.