d3.js - chartJs:当我将鼠标悬停在其中一个点时,我想显示两个数据集图例?
问题描述
我是新手。另外,我从 1 月到 12 月开始使用硬代码标签。我如何将标签从一月到现在。另一个问题是,当我将鼠标悬停到某个点时,您可以在图片中看到。仅显示该点工具提示我想查看位于同一条线上的所有点工具提示
代码
var ctx = document.getElementById("myChart");
ctx.height = 50;
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: monthNames,
datasets: [{
label: "Sales",
data: [2000, 1200, 3000, 5000, 1000, 1300],
pointHoverBackgroundColor: 'rgb(255, 99, 132)',
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
},
{
label: "gross sales",
data: [1500, 2200, 3000, 2800, 1122, 2345],
pointHoverBackgroundColor: 'rgb(66, 133, 244)',
backgroundColor: [
'rgb(66, 133, 244, 0.2)',
],
borderColor: [
'rgb(66, 133, 244)',
],
borderWidth: 1
}]
},
options: {
title:{
display: "true",
text: "Sales Reports",
fontSize: "22"
},
tooltips:{
intersect: false
},
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
解决方案
您可以设置悬停相交属性来实现此目的。这是给你的小提琴-> http://jsfiddle.net/6n3w0qkh/5/。
希望能帮助到你!
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['A', 'B', 'C', 'D', 'E', 'F'],
datasets: [{
label: "Sales",
data: [2000, 1200, 3000, 5000, 1000, 1300],
pointHoverBackgroundColor: 'rgb(255, 99, 132)',
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
},
{
label: "gross sales",
data: [1500, 2200, 3000, 2800, 1122, 2345],
pointHoverBackgroundColor: 'rgb(66, 133, 244)',
backgroundColor: [
'rgb(66, 133, 244, 0.2)',
],
borderColor: [
'rgb(66, 133, 244)',
],
borderWidth: 1
}]
},
options: {
title:{
display: "true",
text: "Sales Reports",
fontSize: "22"
},
tooltips: {
mode: 'index',
intersect: false
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
推荐阅读
- php - 我如何阅读这个对象的内容
- python - 如何将 python pandas 中的日期格式从 mm/dd/yyyy 更改为 dd-mmm-yyyy
- visual-studio-2017 - 如何在 Visual Studio 项目中定位 Windows 10 IoT Core 17763?
- angular - 我如何在第一次登录时读取基本身份验证令牌?
- python - tuplex.count(1) 为 tuplex = ('abc', 1, True, 'abc', 23, 1) 返回 3
- android - 转换 Flowables
- 可流动
- > 或其他可观察到的
- 可流动
- javascript - React 路由器在客户端不工作。我如何解决它?
- google-sheets - 如何根据下一列和单元格(数字-1)自动填充数字?
- reactjs - 带有 React 和 ref 的 FusionCharts
- php - Instagram Graph API - 提及 API - Webhook 如何测试