我只想为一个数据集更改默认的Chartjs工具提示。我有以下代码:
var chart_g3 = new Chart(ctx_g3, {
type: chart_g3_type,
data: {
labels: chart_g3_labels,
datasets: [{
label: 'Watched',
data: g3_data_watch,
backgroundColor: "blue",
},
{
label: 'Threshold',
data: g3_data_threshold,
backgroundColor: "transparent",
borderColor: "orange",
type: 'line',
tooltips: {
enabled: true,
position: 'nearest',
mode: 'single',
callbacks: {
title: function (tooltipItem, data) {
return "Day " + data.labels[tooltipItem[0].index];
},
label: function(tooltipItems, data) {
return "Total: " + tooltipItems.yLabel + ' €';
},
footer: function (tooltipItem, data) { return "..."; }
}
}
}]
},
options: common_options
});
我想修改为g3_data_threshold
行点显示的工具提示,但是上面的代码不起作用。我认为是因为tooltips
属性是Chart
对象的属性,而不是datasets
对象的属性,但是,如果是这样,我如何仅为一个数据集更改渲染的工具提示?
预先感谢