[Chartjs]-Stacked Floating Horizontal Bar using ChartJS

5👍

The reason is that you’re stacking the values on the xAxis.

Simply define xAxis as follows and you get the result you’re expecting.

xAxes: [{
  stacked: false,
}]
window.myBar = new Chart(document.getElementById('canvas'), {
  type: 'horizontalBar',
  data: {
    labels: [1],
    datasets: [{
        label: 'data 1',
        data: [[-3, 5], [6, 8], [10, 11]],
        backgroundColor: 'lightblue'
      },
      {
        label: 'data 2',
        data: [[6, 8]],
        backgroundColor: 'lightblue'
      },
      {
        label: 'data 3',
        data: [[10, 11]],
        backgroundColor: 'lightblue'
      }
    ]
  },
  options: {
    responsive: true,
    scales: {
      xAxes: [{
        stacked: false,
      }],
      yAxes: [{
        stacked: true,
      }]
    },
    legend: {
      position: 'top',
    },
    title: {
      display: true,
      text: 'Horizontal Floating Bars'
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="canvas" height="80"></canvas>

Leave a comment