score:18

Accepted answer

i believe you can get the result you want by using the max parameter on the ticks configuration of the x axes.

by using 2 different x axes with different maximums you can label the bars differently from how they're drawn. resulting in labeling the marks in between the bars without drawing an extra "empty" bar.

var ctx = document.getelementbyid("mychart").getcontext('2d');
var datavalues = [12, 19, 3, 5];
var datalabels = [0, 1, 2, 3, 4];
var mychart = new chart(ctx, {
  type: 'bar',
  data: {
    labels: datalabels,
    datasets: [{
      label: 'group a',
      data: datavalues,
      backgroundcolor: 'rgba(255, 99, 132, 1)',
    }]
  },
  options: {
    scales: {
      xaxes: [{
        display: false,
        barpercentage: 1.3,
        ticks: {
            max: 3,
        }
     }, {
        display: true,
        ticks: {
            autoskip: false,
            max: 4,
        }
      }],
      yaxes: [{
        ticks: {
          beginatzero:true
        }
      }]
    }
  }
});
canvas { max-width: 200px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.7.2/chart.min.js"></script>
<canvas id="mychart" width="20" height="20"></canvas>


Related Query

More Query from same tag