Chartjs-Charts.js line chart, how to hide y-axis start and end label if data is same

4👍

Hope this helps you:
(It hides first and last labels in y axis)

var myChart2 = new Chart(document.getElementById("canvas2"), {
  type: 'bar',
  data: data,
  options: {
   responsive: true,
title: {
  display: true,
  text: "Chart.js - Modified Chart Hiding Min/Max"
},
tooltips: {
  mode: 'index',
  intersect: false
},
legend: {
  display: false,
},
scales: {
  yAxes: [{
    afterTickToLabelConversion: function(scaleInstance) {
      // set the first and last tick to null so it does not display
      // note, ticks[0] is the last tick and ticks[length - 1] is the first
      scaleInstance.ticks[0] = null;
      scaleInstance.ticks[scaleInstance.ticks.length - 1] = null;

      // need to do the same thing for this similiar array which is used internally
      scaleInstance.ticksAsNumbers[0] = null;
      scaleInstance.ticksAsNumbers[scaleInstance.ticksAsNumbers.length - 1] = null;
    },
    ticks: {
      min: 10,
      max: 90,
    },
  }],
}
 }});

complete code on : https://codepen.io/jordanwillis/pen/jBeWWN

Leave a comment