I am using ChartJS library to create charts. In the tooltip, I am showing the data value from the dataset I created. It works in case if the chart type is doughnut. Otherwise it doesn't work in case or bar or horizontalbar charts.
Whatever I do it shows the data with the labels.
Working JSFiddle of Doughnut Chart with data in tooltip.
Working JSFiddle of Bar Chart with label + data in tooltip.
All I want to do is to remove the label shown in the tooltips of the bar chart.
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: [
"Men",
"Women",
"Unknown"
],
datasets: [{
label: 'Men',
data: [60, 40, 20],
backgroundColor: [
'rgba(158, 216, 202, 0.75)',
'rgba(255, 150, 162, 0.75)',
'rgba(160, 160, 160, 0.75)'
]
},
{
label: 'Women',
data: [40, 70, 10],
backgroundColor: [
'rgba(158, 216, 202, 0.5)',
'rgba(255, 150, 162, 0.5)',
'rgba(160, 160, 160, 0.5)'
]
},
{
label: 'Unknown',
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) {
var datasetLabel = '';
var label = data.labels[tooltipItem.index];
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>
just use the title
option with an empty value. Like this:
callbacks: {
title: function(tooltipItems, data) {
return '';
},
label: function(tooltipItem, data) {
var datasetLabel = '';
var label = data.labels[tooltipItem.index];
return data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
}
}
see updated jsfiddle
this is how to get it done
tooltip: {
enabled: true,
displayColors:false,
callbacks: {
label:(tooltipItem)=>{
return tooltipItem.parsed;
},
}
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With