Is there any configuration in chart.js v2 that allows bar's to start from some number instead of origin?

1👍

This can be accomplished with floating bars where individual bars are specified with the syntax [min, max].

Given a data array, its values can easily be converted to the desired data property through the Array.map() method.

data: data.map(v => ([0, v]))

Please take a look at below runnable sample and see how it works.

var data = [-5, -7, -3, -6, -2, -4, -3];

new Chart('myChart', {
  type: 'bar',
  data: {
    labels: ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
    datasets: [{
      label: 'My Bars',
      backgroundColor: ["rgba(255, 99, 132, 0.2)", "rgba(255, 159, 64, 0.2)", "rgba(255, 205, 86, 0.2)", "rgba(75, 192, 192, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(153, 102, 255, 0.2)", "rgba(201, 203, 207, 0.2)"],
      borderColor: ["rgb(255, 99, 132)", "rgb(255, 159, 64)", "rgb(255, 205, 86)", "rgb(75, 192, 192)", "rgb(54, 162, 235)", "rgb(153, 102, 255)", "rgb(201, 203, 207)"],
      borderWidth: 1,
      data: data.map(v => ([0, v]))
    }]
  },
  options: {
    scales: {
      xAxes: [{
        position: 'top'
      }]
    },
    tooltips: {
      callbacks: {
        label: tooltipItem => data[tooltipItem.index]
      }
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js"></script>
<canvas id="myChart"></canvas>

Leave a comment