[Chartjs]-Chart.js How to align two X-axis in bar chart?

2👍

You may be looking after the offset option

Example with multiple datasets:

var myChart = new Chart(ctx, {
  type: 'bar',
  data: {
    labels: ['A', 'B', 'C', 'D', 'E'],
    datasets: [{
      label: 'somelabel',
      xAxisID:'bar-x-axis1',
      data: [40, 50, 30, 12, 52]
    },
    {
      // ... other dataset...
    }]
  },
  options:{
    scales:{
      xAxes:[
        {
          id:'bar-x-axis1',
          type:'category',
          offset: true // <== that one!
        },
        {
          // ... other X axis...
        }]
    }
  }
});

http://www.chartjs.org/docs/latest/axes/cartesian/

0👍

Make your bar graph contains proper groupSpace, barSpace, barWidth

(groupSpace * barSpace) * n + groupSpace = 1

Make this equation is correct, given n is the number of bars

Leave a comment