如何使用chart.js在时间轴上突出显示/格式化特定日期标签(例如今天)?

我有一个x轴为时间线的图表。以下是ChartOptions的相关摘录:

scales:
      {
        xAxes:
          [
            {
              display: true,type: 'time',time: {
                unit: this.shortPeriod ? 'day' : 'week',displayFormats: {
                  day: 'ddd',week: '[W] W'
                },isoWeekday: true,display: false,tooltipFormat: 'dddd DD. MMM'
              }
            }
          ]
       }

一周的示例:

如何使用chart.js在时间轴上突出显示/格式化特定日期标签(例如今天)?

现在,我想调整/格式化特定的日期标签,例如

  1. 将今天的日期替换为“今天”标签
  2. 将字体粗细增加到bold

有什么想法可以实现吗?

wqh467212692 回答:如何使用chart.js在时间轴上突出显示/格式化特定日期标签(例如今天)?

您可以应用任何想要返回文本“ Today”的自定义格式:https://www.chartjs.org/docs/latest/axes/labelling.html#creating-custom-tick-formats

在3.0(当前为Alpha版)中,您可以使用可编写脚本的刻度选项对您选择的粗体进行单个刻度:

fontStyle: function(context) {
        return context.index === 0 ? 'bold' : undefined;
},

https://www.chartjs.org/docs/next/axes/styling.html#tick-configuration

本文链接:https://www.f2er.com/2543384.html

大家都在问