如何隐藏chart.js的标签

问题描述

我有显示 3 种类型标签的图表

enter image description here

我想保留其中两个,并想隐藏一个发票收入报告。我怎样才能隐藏那个标签?我正在使用 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
      }
    },}
});

解决方法

chart.js 中,您可以使用图例属性隐藏标签。在chart.js

options中添加如下代码
legend: {
    display: false
}

根据您的代码,添加图例后,选项将是 .....

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

在选项配置中添加图例选项,将显示设置为false:

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

docs3:https://www.chartjs.org/docs/latest/configuration/legend.html 文档 2:https://www.chartjs.org/docs/2.6.0/configuration/legend.html

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...