3

When creating a bar chart in Chart.js all bars take up the whole horizontal space. How can I add some padding to the most left and most right bar to achieve what you see in the image below:

enter image description here

Alternativly this may be achieved if the bars are aligned in the center and using a max-width in percentage on the bars itself, so that they will never fill up the whole space. But I can't find any options for that either.

Currently I'm adding two 0 values with blank labels on each side, which works, but it's just a workaround:

var data = {
    labels: ['', '', 1, 2, 3, '', ''],
    datasets: [{
        data: [0, 0, 36500, 59000, 65000, 0, 0],

        backgroundColor: [
              null,null,
              'blue','blue','blue',
              null,null
        ],
    }]
};

I'm using Chart.js 2.3.

lampshade
  • 2,470
  • 3
  • 36
  • 74

0 Answers0