1๐
โ
You need to use options.scales.yAxes[0].ticks.callback
function
render() {
const options = {
responsive: true,
legend: {
display: false
},
type: "bar",
scales: {
yAxes: [{
ticks: {
callback: function(value, index, values) {
if (index % 2 === 0) {
return value;
}
return null;
}
}
}]
}
};
}
1๐
Note: @Catalin โs answer is problematic. Problem: He/She is returning ""
in case the label should be hidden. However, you should return null
.
Generalized answer
You need to use the options.scales.yAxes.ticks.callback
function
const options = {
scales:{
yAxes: {
ticks: {
callback: function(value, index, values) {
if (index % 2 === 0) {
return value;
}
return null; // <- NOT ""
}
}
}
}
}
Why is null
so important?
The impact becomes clear on the xAxes:
Returning null
tells chartjs that there is no label.
Returning ""
tells chartjs that there is a label. That means, it reserves space. In this case the labels are slanted:
Source:stackexchange.com