Chartjs-Chart.js horizontalBar customization

0👍

Actually there’s no way to create such a chart with chartJS framework. So I had to manipulate the chart data (and colors) with js to get the results.
If someone is interested in more details I’m available.

0👍

Drawing bars with different orientation can be done with floating bars. Individual bars are specified with the syntax [min, max]. This feature was introduced with Chart.js v2.9.0.

new Chart(document.getElementById('canvas'), {
  type: 'horizontalBar',
  data: {
    labels: [1, 2, 3, 4],
    datasets: [{
      label: 'data',
      data: [[-3, 0], [0, 6], [-4, 0], [0, 5]],
      backgroundColor: ['red', 'blue', 'green', 'orange']
    }]
  },
  options: {
    responsive: true,
    legend: {
      display: false
    },
    title: {
      display: false
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="canvas" height="90"></canvas>

Leave a comment