5

I have chart which show 3 types of label

enter image description here

I want to keep two of them and want to hide one Invoice Income Report. How can I hide that one label? I am using chart.js v2

var myChart = new Chart(ctx, {
  type: 'bar',
  data: {
    labels: labels,
    datasets: [{
      label: 'Invoice Income Report',
      data: bar_chart_data,
      backgroundColor: colors,
      borderWidth: 1
    }, {
      label: 'Below Average',
      backgroundColor: ['rgba(255, 99, 132, 1)']
    }, {
      label: 'Above Average',
      backgroundColor: ['rgba(11, 156, 49, 1)']
    }]
  },
  options: {
    scales: {
      y: {
        beginAtZero: true
      }
    },
  }
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Bilal Arshad
  • 51
  • 1
  • 2

4 Answers4

1

Add legend option to options configuration, set display to false:

                , options: {
                    scales: {
                        y: {
                            beginAtZero: true
                        }
                    },
                    legend: {
                      display: false
                    }
                }

Consider the docs v3 or docs v2.

Cadoiz
  • 1,446
  • 21
  • 31
guolei1998
  • 27
  • 2
  • either the scales or legend wont work in this current config. This is V2 and V3 syntax combined – LeeLenalee Oct 07 '22 at 09:23
  • For me it works fine. I use wkhpdf to convert html to pdf and plugins don't work for me, so this is the perfect solution. – Cadoiz Apr 06 '23 at 06:18
1

You can simply make display false.

const options = {
    responsive: true,
    plugins: {
      legend: {
        position: 'top' as const,
        display: false,
      },
      title: {
        display: false,
        text: 'Chart.js Line Chart',
      },
    },
  };
Conda
  • 141
  • 1
  • 2
  • 12
1

To hide the labels on version 4.2.1 of chart.js use this:

// Example chart.
const chart = new Chart(id, {
        type: 'bar', // Chart type.
        data: data, // Your data.

        options: {
            // Add plugins to options.
            plugins: {
                legend: {
                    display: false // This hides all text in the legend and also the labels.
                }
            }
            // add your scales or other options.
        }
    });

For more info use the doc: https://www.chartjs.org/docs/latest/configuration/legend.html

Justin
  • 103
  • 1
  • 10
0

In chart.js, You can hide the labels using legend attribute. Add the following code in options of chart.js

legend: {
    display: false
}

According to your code, after adding legend the options will be .....

options: {
    scales: {
        y: {
            beginAtZero: true
        }
    },
    legend: {
        display: false
    }
}
John Doe
  • 1,401
  • 1
  • 3
  • 14