score:4

you can provide a labels array padded with empty strings to the required length, e.g. 15.

this will ensure a consistent number of categories on the axis, and thus ensure that the bars will stay the same width and left-aligned even when there are less bars (fiddle).

(if you like, you can also pad the data array with 0's for consistency, but it's not necessary - the labels array is what determines the axis looks like.)

var data = [12, 19, 3, 5, 2];
var labels = ["a", "b", "c", "d", "e"];

for (var i = labels.length; i < 15; i++) {
  labels.push("");
}

var ctx = document.getelementbyid("mychart");
var mychart = new chart(ctx, {
  type: 'bar',
  data: {
    labels: labels,
    datasets: [{
      label: 'count',
      data: data
    }]
  },
  options: {
    scales: {
      yaxes: [{
        ticks: {
          beginatzero: true
        }
      }]
    }
  } 
});

Related Query

More Query from same tag