Chartjs-How do remove the bottom scale on a Chart.js bar chart

1๐Ÿ‘

var dataArr = [154.23, 203.21, 429.01, 637.41];
var chart = new Chart(ctx, {
  type: 'horizontalBar',
  data: {
    labels: [154.23, 203.21, 429.01, 637.41],
    datasets: [{
      label: 'LINE',
      data: dataArr,
      backgroundColor: 'rgba(0, 119, 290, 0.2)',
      borderColor: 'rgba(0, 119, 290, 0.6)',
      fill: false,
      tension: 0
    }]
  },
  options: {
    scales: {
      xAxes: [{
        ticks: {
          min: Math.min.apply(this, dataArr),
          max: Math.max.apply(this, dataArr),
          callback: function(value, index, values) {
            if (index === values.length - 1) return Math.min.apply(this, dataArr);
            else if (index === 0) return Math.max.apply(this, dataArr);
            else return '';
          }
        }
      }]
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>

<canvas id="ctx"></canvas>

Leave a comment