Accepted answer

based on the code that you supplied in your question, it looks like you forgot to add labels data in your chart data object. without this information chartjs is not able to generate your axis and map each dataset data to it.

also, since you mentioned you wanted the legend to be below the chart, i added the display: bottom option. here is the working code.

var ctx = document.getelementbyid("mybarchart").getcontext("2d");

var mybarchart = new chart(ctx, {
  type: 'bar',
  data: {
    labels: ['votes'],
    datasets: [{
      label: '# of votes',
      backgroundcolor: "#000080",
      data: [80]
    }, {
      label: '# of votes2',
      backgroundcolor: "#d3d3d3",
      data: [90]
    }, {
      label: '# of votes3',
      backgroundcolor: "#add8e6",
      data: [45]

  options: {
    legend: {
      display: true,
      position: 'bottom',
      labels: {
        fontcolor: "#000080",
    scales: {
      yaxes: [{
        ticks: {
          beginatzero: true

here is a working codepen example as well.


with the latest version of the chart.js (3.6.0), you can control the legend display with the following code:

  const options = {
    plugins: {
      legend: {
        position: "right", // by default it's top

i know this has been here for so long but might help someone who faced the same issue as me in the future.

Related Query

More Query from same tag