Chart.js 时间刻度:在 xAxes 上设置最小值和最大值刻度、最大值、最小值、时间

2023-09-07 11:42:04 作者:探探四个字

如何在 xAxes 上设置最小值和最大值?它在 yAxes 上运行良好,但在 xAxes 上却没有表现出任何行为.

How can I set a min and max on the xAxes? It works fine on the yAxes but on the xAxes it shows no behavior.

我的 xAxes 正在使用 type: 'time'.我的 xAxis 标签也在使用 moment 对象.但是当我删除类型时间并使用普通数字时它也不起作用.我使用的是 Chart.js 版本 2.2.2.

My xAxes is using the type: 'time'. My labels for the xAxis are using the moment object aswell. But it also does not work when I remove the type time and use normal digits. I am using the Chart.js version 2.2.2.

scales: {
   yAxes: [{
      ticks: {
         beginAtZero:false,
      }
   }],
   xAxes: [{
      type: 'time',
      ticks: {
         min: moment(1471174953000),
         max: moment(1473853353000)
      }   
   }]
}

这里是 chart.js 时间刻度文档.

推荐答案

您要查找的属性实际上在 time 属性中:

The properties you are looking for actually are in the time attribute :

options: {
    scales: {
        xAxes: [{
            type: "time",
            time: {
                min: 1471174953000,
                max: 1473853353000
            }
        }]
    }
}