score:1

Accepted answer

they fixed this issue in v3 so upgrading to that is 1 solution, the other one is downgrading to version 2.8, in a git issue on their repo someone posted a workaround but that only works till version 2.8.

v3: horizontalbar has been removed as a type, use bar chart instead and set the index axis to y in your options

example:

var options = {
  type: 'bar',
  data: {
    labels: ["red", "blue", "yellow", "green", "purple", "orange"],
    datasets: [{
        label: '# of votes',
        data: [12, 19, 3, 5, 2, 3],
        borderwidth: 1
      },
      {
        type: 'line',
        label: '# of points',
        data: [7, 11, 5, 8, 3, 7],
        borderwidth: 1
      }
    ]
  },
  options: {
    indexaxis: 'y'
  }
}

var ctx = document.getelementbyid('chartjscontainer').getcontext('2d');
new chart(ctx, options);
<body>
  <canvas id="chartjscontainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.2.0/chart.js"></script>
</body>

v2 solutions, for if stuck on v2 with plugin support to achieve this in 2.8 you will have to specify your data as objects and specify the x and y coordinates

example:

var ctx = document.getelementbyid("mychart");
var mychart = new chart(ctx, {
  type: 'horizontalbar',
  data: {
    datasets: [{
      label: "clients signed",
      data: [2, 0, 3, 5, 1, 3, 6, 5, 3, 10]
    }, {
      label: "quota",
      data: [{
        x: 2,
        y: 'q2 2015'
      }, {
        x: 2,
        y: 'q3 2015'
      }, {
        x: 2,
        y: 'q4 2015'
      }, {
        x: 2,
        y: 'q1 2016'
      }, {
        x: 2,
        y: 'q2 2016'
      }, {
        x: 2,
        y: 'q3 2016'
      }, {
        x: 2,
        y: 'q4 2016'
      }, {
        x: 2,
        y: 'q1 2017'
      }, {
        x: 2,
        y: 'q2 2017'
      }, {
        x: 2,
        y: 'q3 2017'
      }],
      type: 'line'
    }],
    labels: ["q2 2015", "q3 2015", "q4 2015", "q1 2016", "q2 2016", "q3 2016", "q4 2016", "q1 2017", "q2 2017", "q3 2017"]
  },
  options: {
    barpercentage: 1.0,
    categorypercentage: 1.0
  }
});
<body>
  <div class="mychartdiv">
    <canvas id="mychart" width="600" height="400"></canvas>
  </div>
  <script src="https://npmcdn.com/chart.js@2.8.0/dist/chart.bundle.min.js"></script>
</body>

git issue: https://github.com/chartjs/chart.js/issues/4096


Related Query

More Query from same tag