X轴标签未显示在chart.js

时间:2020-03-01 06:13:00

标签: javascript charts chart.js

下面是我需要绘制的两个图表。使用我的配置,X轴标签没有出现。我不知道为什么会这样。

我的X轴标签是时间序列。

"scales": {
  "xAxes": [
    {
      "type": "time",
      "unitStepSize": 1,
      "time": {
        "unit": "day"
      },
      "displayFormats": {
        "day": "MMM DD"
      },
      "distribution": "series",
      "gridLines": {
        "display": true,
        "drawBorder": true,
        "drawOnChartArea": true,
        "tickMarkLength": 15
      },
      "stacked": false
    }
  ]
}


"labels": [
  "2020-02-27 12:00:25",
  "2020-02-27 15:00:27"
]

下面是没有显示X轴标签的图表

在这里拨弄:https://jsfiddle.net/dilani_m/2bercd8p/1/

enter image description here

在这里拨弄:https://jsfiddle.net/dilani_m/rmz5kq4t/6/

enter image description here

1 个答案:

答案 0 :(得分:0)

您具有正确的代码和实现,但是反馈到图表的数据不足以呈现x轴标签。对于前。下面的labels是同一天,而Unit Step Size1 Day。因此,默认情况下,图表不会为2个数据点呈现同一天的标签。

"labels": [
  "2020-02-27 12:00:25",
  "2020-02-27 15:00:27"
]

您可以看到有效的小提琴here