我有一张用图表做的条形图.js使用两个数据集,标签如下所示.
<div><canvas id="myChart"></canvas></div>
图表的JS如下所示
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, ',');
}
}
}
]
},
},
});
但是,当我将鼠标悬停在其中一个栏上时,realisasi的工具提示不会显示,它只显示目标的工具提示,同时,当我将鼠标悬停在目标栏或realisasi栏上时,我需要同时显示两个工具提示.我怎样才能解决这个问题?