如何在图表JS中的线图中的整个线中悬停效应
ngOnInit(): void {
var myChart = new Chart('myChart', {
type: 'bar',
data: {
labels: ['Modes'],
datasets: [
{
label: 'A',
data: [this.data.a],
borderColor: 'rgba(255,105,180,1)',
backgroundColor: 'rgba(255,105,180,0.2)',
barPercentage:0.4,
borderWidth:2,
order: 1
},
{
label: 'B',
data: [this.data.b],
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
barPercentage:0.4,
borderWidth:2,
order: 2
},
{
label: 'Total Recordings',[![image of current scenario][1]][1]
data:[this.data.totalrecordings,this.data.totalrecordings],
type:'line',
borderColor:'rgba(2,117,216,1)',
backgroundColor:'rgba(2,117,216,0.2)',
pointRadius:0,//3,
pointHoverRadius:0,//4,
xAxisID:'xAxis2',
order:0
}
]
},
options: {
responsive: true,
//hover:{
//mode:'index',
// intersect:false
//},
plugins: {
legend: {
position: 'top',
},
tooltip:{
mode:'index',
callbacks:{
title:(ttItems)=> (ttItems[0].dataset.type === 'line' ? '' : ttItems[0].label)
},
}
},
scales:{
xAxis:{},
xAxis2:{
display:false,
offset:false,
labels:[' ',' ']
}
}
},
})
}
我希望,当我将悬停在线图上的任何位置时,它应该显示数据。现在,只有当我悬停在一开始或末尾时,只有我才能看到数据。同样,在悬停时,我可以看到总记录值的值,但是在悬停时,我就可以看到所有数据集的值。任何输入都会有很大帮助
ngOnInit(): void {
var myChart = new Chart('myChart', {
type: 'bar',
data: {
labels: ['Modes'],
datasets: [
{
label: 'A',
data: [this.data.a],
borderColor: 'rgba(255,105,180,1)',
backgroundColor: 'rgba(255,105,180,0.2)',
barPercentage:0.4,
borderWidth:2,
order: 1
},
{
label: 'B',
data: [this.data.b],
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
barPercentage:0.4,
borderWidth:2,
order: 2
},
{
label: 'Total Recordings',[![image of current scenario][1]][1]
data:[this.data.totalrecordings,this.data.totalrecordings],
type:'line',
borderColor:'rgba(2,117,216,1)',
backgroundColor:'rgba(2,117,216,0.2)',
pointRadius:0,//3,
pointHoverRadius:0,//4,
xAxisID:'xAxis2',
order:0
}
]
},
options: {
responsive: true,
//hover:{
//mode:'index',
// intersect:false
//},
plugins: {
legend: {
position: 'top',
},
tooltip:{
mode:'index',
callbacks:{
title:(ttItems)=> (ttItems[0].dataset.type === 'line' ? '' : ttItems[0].label)
},
}
},
scales:{
xAxis:{},
xAxis2:{
display:false,
offset:false,
labels:[' ',' ']
}
}
},
})
}
I want that when I hover anywhere on the line chart it should show the data. Right now only when I hover over the very start or the end of the line then only I can see data. Also at the end of the line when I hover I can just see the total recordings value but in the start when I hover I am able to see value of all the datasets. Any input would be of great help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用单个浮子栏使用
dataset
,而不是使用行,可以将其定义如下:与此相同:与此一起,您需要定义
tooltip.callbacks.label < /代码>正确报告
TotalRecordings
的功能。请查看您的修订代码,看看它是如何工作的。
Instead of using a line, you could use a
dataset
with a single floating bar that can be defined as follows:Together with this, you'll need to define a
tooltip.callbacks.label
function that correctly reportstotalrecordings
.Please take a look at your amended code and see how it works.