Chart.js -以“天”为单位在x轴上呈现时间图

vohkndzv  于 2022-11-06  发布在  Chart.js
关注(0)|答案(1)|浏览(252)

我使用的是Chart.js(2.7),我将日期以ISO格式保存在labels数组中,我还尝试将它们保存为毫秒刻度,并且我的数据集的数据是随机正整数。
我的图形配置如下所示:

  1. {
  2. type: 'bar',
  3. data: {
  4. datasets: [] as any[],
  5. labels: [] as string[]
  6. },
  7. options: {
  8. legend: {
  9. display: false
  10. },
  11. maintainAspectRatio: false,
  12. plugins: {
  13. legend: {
  14. position: 'top',
  15. }
  16. },
  17. scales: {
  18. xAxes: [{
  19. ticks: {
  20. autoSkip: true
  21. },
  22. scaleLabel: {
  23. display: true,
  24. labelString: 'Pinged At (Date and Time)'
  25. },
  26. type: "time",
  27. time: {
  28. unit: 'day',
  29. unitStepSize: 1,
  30. stepSize: 1
  31. }
  32. }],
  33. yAxes: [{
  34. scaleLabel: {
  35. display: true,
  36. labelString: 'Response Time (ms)'
  37. }
  38. }]
  39. }
  40. }
  41. }

这不会呈现任何内容!它会检测标签的内容:

但是没有数据点。但是,当我将单位设置为小时,然后显示数据时,它工作得很好。
我的标签数组包含如下数据点:[“2022年6月30日星期一16:24:07.713+05:00”,“2022年7月7日星期一15:23:02.742+05:00”]
我的数据点是这样的:【一、十一】
谁能告诉我,我是否在配置上犯了任何错误?

ffvjumwh

ffvjumwh1#

如果你正在推送你的数据集,你需要在之后调用myChart.update()。当我没有得到数据点时,这是我的第一个想法。

相关问题