折线图JS中的工具提示回调不起作用



我正在使用折线图js来显示图形,并试图计算所选点与上一个点之间的差异,并在工具提示中渲染它。

我读到我应该使用回调函数,但当我尝试它时,什么也没发生。

就连我也只是想改变一下如果有人能帮忙的话,下面是我的折线图选项:(Chart-js版本:3.6.1

plugins: {
legend: {
display: false
},
title: {
display: true,
font: {
size: 18,
},
color: "white"
},
zoom: {
zoom: {
drag: {
enabled: true
},
mode: 'xy',
}
},
tooltip: {
callbacks: {
title: function () {
return "my tittle";
}
}
}
}

这是因为在V3中使用V2语法,所以可以读取选项中的命名空间。

工具提示已移至插件部分

对于所有更改,请阅读迁移指南

const options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderColor: 'orange'
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderColor: 'pink'
}
]
},
options: {
plugins: {
tooltip: {
callbacks: {
title: () => ('Title')
}
}
}
}
}
const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.2/chart.js"></script>
</body>

最新更新