简体   繁体   English

如何使用 Chart.js 在 X 轴上显示带有网格线的刻度线和标签?

[英]How to show tick marks and labels with grid line for the specific one on the X axis with Chart.js?

Thank you for paying attention to this question.感谢您关注这个问题。

I'd like to add the ticks and 3 labels with the gridline like the picture but I couldn't find the best solution to make the X-axis like the picture.我想像图片一样添加带有网格线的刻度线和 3 个标签,但我找不到使 X 轴像图片一样的最佳解决方案。 Hope someone helps me.希望有人帮助我。

在此处输入图像描述

use this for your labels array:将此用于您的标签数组:

labels: [["jan", 20], "", "", "", "", "", ["jul", 20], "", "", "", "", "", ["jan", 21]],

and this to your options object:这是您的选项 object:

options: {
    scales: {
        xAxes: [{
            ticks: {
               callback: (label) => (label === "" ? null : label)
          }
      }]
    }
  }

will get the following result:将得到以下结果: 在此处输入图像描述

Since the tick marks are getting generated from the grid lines they dissapear too, dont know how you can fix that由于刻度线是从网格线生成的,它们也消失了,不知道如何解决这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM