James
James

Reputation: 2787

Remove specific label

Simple question, but can't seem to find the answer.

How can we remove a specific label on x-axis in chart.js?

This is the curve I currently have:enter image description here

Is there a way to simply hide the 9am while keep showing other label (10am.....)?

Things I tried:

ticks: {
                   
         callback: function(value, index, values) {
               return '';
            }
         }

But this will remove all the label on x-axis.

Any helps will be appreicated

Note: this is not a duplicate of Remove x-axis label/text in chart.js since I want to remove a specific x-label only.

Upvotes: 1

Views: 84

Answers (1)

LeeLenalee
LeeLenalee

Reputation: 31331

You always need to return something. So you can first check if the current label is 9am if so return an empty string otherwise return the label:

ticks: {
  callback: function(value, index, values) {
    const label = this.getLabelForValue(value)
    return label === '9am' ? '' : label;
  }
}

Upvotes: 1

Related Questions