I have a bar diagram made with chart.js that's using two datasets and for the labels that looks like this.
<div><canvas id="myChart"></canvas></div>
and the JS for the chart looks like this
const target = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100];
const realisasi = [0, 0, 0, 0, 0, 10, 0, 10, 1, 0, 0, 0];
const ctx = document.getElementById("myChart").getContext("2d");
const dataset = {
labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
datasets: [
{ label: "Target", data: target, backgroundColor: "#3d8ef8" },
{ label: "Realisasi", data: testArr, backgroundColor: "#11c46e" },
],
}
const myChart = new Chart(ctx, {
type: 'bar',
data: dataset,
options: {
tooltips: {
callbacks: {
data (t, d) {
const xLabel = d.datasets[t.datasetIndex].label;
const yLabel = t.yLabel >= 1000 ? 'Rp.' + t.yLabel.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') : '$' + t.yLabel;
return xLabel + ': ' + yLabel;
}
}
},
scales: {
yAxes: [
{
ticks: {
beginAtZero: true,
callback: (label, index, labels) => {
return 'Rp.' + label.toFixed(0).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
}
}
]
},
},
});
however the tooltips for the realisasi won't show up when I hover on one of the bar, it only shows the tooltips for the target meanwhile I need to make both tooltips appear when I hover either on the target bar or the realisasi bar. how can I fix that?