ChartJS 如何从charts.js中删除标签

bprjcwpo  于 2022-11-06  发布在  Chart.js
关注(0)|答案(1)|浏览(255)

我正在使用charts.js为我的网站创建一个图表。我无法从图表中删除图例。x1c 0d1x
我没有找到解决方案。这是我第一次使用chartsiderjs库。
密码:

  1. const ctx1 = document.getElementById('yearWise').getContext('2d');
  2. const yearWise = new Chart(ctx1, {
  3. type: 'bar',
  4. plugins: [ChartDataLabels],
  5. data: {
  6. legend: 'options',
  7. labels: ['2018-19','2019-20','2020-21','2021-22'],
  8. datasets: [{
  9. data: [90,400,5245,5122],
  10. backgroundColor: [
  11. // 'rgba(255, 99, 132, 0.5)',
  12. 'rgba(70, 132, 238, 0.5)',
  13. ],
  14. borderColor: [
  15. // 'rgba(255, 99, 132, 1)',
  16. 'rgba(70, 132, 238, 1)',
  17. ],
  18. borderWidth: 1
  19. }]
  20. },
  21. options: {
  22. legend: {
  23. display: false,
  24. },
  25. responsive: true,
  26. scales: {
  27. y: {
  28. beginAtZero: true,
  29. }
  30. },
  31. plugins: {
  32. title: {
  33. display: true,
  34. text: 'Programs Conducted - Year Wise',
  35. },
  36. datalabels: {
  37. anchor: 'end',
  38. align: 'end',
  39. labels: {
  40. value: {
  41. color: 'rgba(70, 132, 238, 1)'
  42. }
  43. }
  44. },
  45. },
  46. }

});提前感谢。

u7up0aaq

u7up0aaq1#

以下是https://www.chartjs.org/docs/latest/configuration/legend.html文档
只需将legend.display设置为false即可。

  1. options: {
  2. plugin: {
  3. legend: {
  4. display: false,
  5. }
  6. }
  7. }

您可以在此处尝试https://codesandbox.io/s/wonj2xn23w?file=/src/index.js

相关问题