Ali*_*cia 5 javascript charts chart.js
我正在使用 Chart.js v2.7.2 并想删除“标签”字段。离开它会返回“未定义”,而我尝试过的各种选项都没有做任何事情。有人对此有新的见解吗?图例、标题等都无法删除它。
let thisChart = new Chart(gov_chart, {
type: 'horizontalBar',
data: {
label: 'I want to remove this',
labels: [data1, data2],
datasets: [{
backgroundColor: ['rgb(240,61,74)', 'rgb(0, 156, 255)'],
data: [data1.count, data2.count],
}]
},
options: {
scales: {
xAxes: [{
ticks: {
beginAtZero: true
}
}]
}
},
legend: {
display: false
},
title: {
display: false
},
tooltips: {
callbacks: {
label: function(tooltipItem) {
return tooltipItem.yLabel;
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
本label应该是内部datasets如
type: 'horizontalBar',
data: {
labels: [data1, data2],
datasets: [{
label: 'put it here', // => here
backgroundColor: ['rgb(240,61,74)', 'rgb(0, 156, 255)'],
data: [data1.count, data2.count],
}]
},
Run Code Online (Sandbox Code Playgroud)
所以你不会得到未定义
更新:
如果您不想看到它,请将legend配置放在options. 显然,我看到你legend是外部options对象。
options: {
legend: {
display: false
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,此答案已过时。要删除图例,您现在必须指定插件。 https://www.chartjs.org/docs/latest/configuration/legend.html
例如
var chart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
plugins: {
legend: {
display: false
}
}
}
Run Code Online (Sandbox Code Playgroud)
});
| 归档时间: |
|
| 查看次数: |
8760 次 |
| 最近记录: |