我正在使用ChartJS库来创建图表 . 在工具提示中,我显示了我创建的数据集中的数据值 . 如果图表类型是甜甜圈,它的作用 . 否则它在大小写或条形或水平条形图中不起作用 .
无论我做什么,它都会显示带有标签的数据 .
Working JSFiddle of Doughnut Chart with data in tooltip .
Working JSFiddle of Bar Chart with label + data in tooltip .
我想要做的就是删除条形图工具提示中显示的标签 .
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: [
"Men",
"Women",
"Unknown"
],
datasets: [{
label: 'Sweden',
data: [60, 40, 20],
backgroundColor: [
'rgba(158, 216, 202, 0.75)',
'rgba(255, 150, 162, 0.75)',
'rgba(160, 160, 160, 0.75)'
]
},
{
label: 'Netherlands',
data: [40, 70, 10],
backgroundColor: [
'rgba(158, 216, 202, 0.5)',
'rgba(255, 150, 162, 0.5)',
'rgba(160, 160, 160, 0.5)'
]
},
{
data: [33, 33, 34],
backgroundColor: [
'rgba(158, 216, 202, 0.25)',
'rgba(255, 150, 162, 0.25)',
'rgba(160, 160, 160, 0.25)'
]
}
]
},
options: {
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
return data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
}
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.bundle.min.js"></script>
<canvas id="myChart" width="400" height="200"></canvas>
1 回答
只需使用带有空值的
title
选项 . 像这样:见updated jsfiddle