如何为 JSON 的 ChartJS 图表设置时间刻度?

How to set a time scale to a ChartJS chart from JSON?

我正在尝试使用 chartJS 编写甘特图代码,但我无法通过在 Ajax 函数中从 json 获取日期来找到如何做到这一点。这是我使用的代码:

$.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);
}
});

所以第 'test4' 行的日志是:

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

这是我得到的:

我不知道我是否可以使用“x2”字段,因为 chartJS 不接受它。所以酒吧是 我猜是从 1970 年开始,停在“x”...

如果我像这样手动输入日期 - data : [['2022-04-06','2022-04-29']] ,而不是我的数组“dates”,它可以工作。 ..

方向正确的任何一点都是最有益的。我也会回答任何问题。

对不起,如果我的英语不完美。

所以我自己找到了答案,就是这样写推送:

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

如果有帮助的话。 如果你想帮助我,谢谢。