Aru*_*esh 9 javascript jquery chart.js
我正在使用图表j来显示分组条形图并尝试隐藏工具提示的标题
代码生成栏
var ctx = document.getElementById("myChart").getContext("2d");
var data = {
labels: ["Chocolate", "Vanilla", "Strawberry"],
datasets: [
{
label: "Blue",
backgroundColor: "blue",
data: [3,7,4]
},
{
label: "Red",
backgroundColor: "red",
data: [4,3,5]
},
{
label: "Green",
backgroundColor: "green",
data: [7,2,6]
}
]
};
var myBarChart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
barValueSpacing: 20,
scales: {
yAxes: [{
ticks: {
min: 0,
}
}]
}
}
});
Run Code Online (Sandbox Code Playgroud)
在工具提示中显示标签巧克力,香草,草莓和我试图隐藏标签与以下
通过将titlefontsize设置为0但它不起作用
tooltipTitleFontSize: 0
Run Code Online (Sandbox Code Playgroud)
我已尝试使用工具提示回调它禁用标签蓝色,红色,绿色,但我不需要
tooltips: {
callbacks: {
label: function(tooltipItem) {
return tooltipItem.yLabel;
}
}
}
Run Code Online (Sandbox Code Playgroud)
提前谢谢你
ɢʀᴜ*_*ᴜɴᴛ 17
要隐藏工具提示的标题,你需要在提示标题返回一个空函数的回调,像这样......
options: {
tooltips: {
callbacks: {
title: function() {}
}
},
...
}
Run Code Online (Sandbox Code Playgroud)
要隐藏工具提示标题/标签,应将其添加到该图表的选项对象中,如下所示:
options: {
plugins: {
tooltip: {
callbacks: {
title : () => null // or function () { return null; }
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
请参阅文档以更好地理解它应该使用自定义回调函数来处理,并且它不是可以直接在选项中设置的配置。https://www.chartjs.org/docs/latest/configuration/tooltip.html#tooltip-callbacks
我在另一个线程中提到了同样的事情:/sf/answers/4762375341/