如何禁用特定数据集图表JS的默认标签
this.myBarChart = new Chart('myBarChart', {
type: 'bar',
data: {
labels: ["Voice Control Mode", "Manual Mode", "Automatic Mode","Single Drive Mode","Dual Drive Mode"],
datasets: [
{
type: 'bar',
label: "Recordings",
backgroundColor: "rgba(2,117,216,1)",
borderColor: "rgba(2,117,216,1)",
data: [this.data.voicecontrolmode, this.data.manualmode, this.data.automaticmode,this.data.singledrivemode,this.data.dualdrivemode],
order:2
},
{
type: 'line',
data: [this.data.totalrecordings, this.data.totalrecordings, this.data.totalrecordings,this.data.totalrecordings,this.data.totalrecordings],
label: 'Total Recordings',
backgroundColor: "rgba(150,29,255,1)",
borderColor: "rgba(150,29,255,1)",
pointRadius:0,
pointHoverRadius:0,
order:1
}
]
},
options: {
// plugins:,
scales: {
xAxis: {
ticks: {
maxTicksLimit: 6
}
},
yAxis: {
ticks: {
maxTicksLimit: 5
}
}
}
}
});
我想删除标签:[“语音控制模式”,“手动模式”,“自动模式”,“单个驱动器模式”,“双驱动模式”]仅适用于线图,以便总记录只是一条直线,但是当我徘徊时,应该说 - 总记录:95(示例)。对于条形图,标签仍应显示。在此处输入图像说明
this.myBarChart = new Chart('myBarChart', {
type: 'bar',
data: {
labels: ["Voice Control Mode", "Manual Mode", "Automatic Mode","Single Drive Mode","Dual Drive Mode"],
datasets: [
{
type: 'bar',
label: "Recordings",
backgroundColor: "rgba(2,117,216,1)",
borderColor: "rgba(2,117,216,1)",
data: [this.data.voicecontrolmode, this.data.manualmode, this.data.automaticmode,this.data.singledrivemode,this.data.dualdrivemode],
order:2
},
{
type: 'line',
data: [this.data.totalrecordings, this.data.totalrecordings, this.data.totalrecordings,this.data.totalrecordings,this.data.totalrecordings],
label: 'Total Recordings',
backgroundColor: "rgba(150,29,255,1)",
borderColor: "rgba(150,29,255,1)",
pointRadius:0,
pointHoverRadius:0,
order:1
}
]
},
options: {
// plugins:,
scales: {
xAxis: {
ticks: {
maxTicksLimit: 6
}
},
yAxis: {
ticks: {
maxTicksLimit: 5
}
}
}
}
});
I want to remove labels: ["Voice Control Mode", "Manual Mode", "Automatic Mode","Single Drive Mode","Dual Drive Mode"] for only the line chart so that total recordings is just a straight line but when I hover over that it should just say- Total Recordings:95(example). For the bar chart the labels should still show up.enter image description here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以添加带有偏移的第二个X轴并将显示设置为false,然后将行映射到该X轴:
编辑:
您可以为此使用自定义工具提示标题回调,请参见上面更新的实时示例。
You can add a second x axis with offset and display set to false, then map your line to that x axis:
EDIT:
You can use a custom tooltip title callback for this, see updated live example above.