score:11

Accepted answer

you can use the following callback function for y-axis ticks to achieve that :

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 '';
}

note: you must use a separate array for data values (here it's dataarr), instead of an in-line one.

edit :

add the following in your y-axis ticks config to make the data-points perfectly aligned with the ticks :

min: math.min.apply(this, dataarr),
max: math.max.apply(this, dataarr)

ᴡᴏʀᴋɪɴɢ ᴇxᴀᴍᴘʟᴇ

var dataarr = [154.23, 203.21, 429.01, 637.41];
var chart = new chart(ctx, {
   type: 'line',
   data: {
      labels: ['jan', 'feb', 'mar', 'apr'],
      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: {
         yaxes: [{
            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>


Related Query

More Query from same tag