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