javascript - 悬停在highchart的同步图表上时线褪色
问题描述
我有一个带有两个不同容器的同步高图。我使用脚本来同步图表。同步工作完美。我的第一个图表有 3 条线,第二个图表只有 1 条线。
当我悬停第一个图表时,第三条线逐渐消失。当我禁用同步脚本时,它工作正常。
这是我的同步脚本。
$('#container, #container2').bind('mousemove touchmove touchstart', function(e) {
var chart,
points,
i,
secSeriesIndex = 1;
for (i = 0; i < Highcharts.charts.length; i++) {
chart = Highcharts.charts[i];
e = chart.pointer.normalize(e); // Find coordinates within the chart
points = [chart.series[0].searchPoint(e, true), chart.series[1].searchPoint(e, true)]; // Get the hovered point
if (points[0] && points[1]) {
if (!points[0].series.visible) {
points.shift();
secSeriesIndex = 0;
}
if (!points[secSeriesIndex].series.visible) {
points.splice(secSeriesIndex,1);
}
if (points.length) {
chart.tooltip.refresh(points); // Show the tooltip
chart.xAxis[0].drawCrosshair(e, points[0]); // Show the crosshair
}
}
}
});
有人可以帮我吗?
解决方案
您需要将所有悬停点添加到points
数组中,而不仅仅是前两个:
for (i = 0; i < Highcharts.charts.length; i++) {
chart = Highcharts.charts[i];
e = chart.pointer.normalize(e); // Find coordinates within the chart
points = [];
chart.series.forEach(function(s) {
points.push(s.searchPoint(e, true));
});
...
}
推荐阅读
- image - 如何使用聊天 api 在whats app 消息中包含和发送图像
- c++ - 如何捕获重复组最多 N 次?
- php - 在 Laravel 中创建删除查询
- angular - Heroku Scheduler 执行时来自 api/router 的套接字 IO 广播 - 如何?
- google-cloud-platform - 如何在 Google Cloud Platform 中捕获集群崩溃和集群启动之间的停机时间
- c# - c# - System.FormatException: 'Guid 应包含 32 位数字和 4 个破折号 (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。'
- mysql - 使用 Laravel Schedule Cronjob 更新数据库
- javascript - 如果脚本已经存在,则从 head 标记中删除脚本
- async-await - Loopback js 连接器使用 async / await
- android - 在 Android 中,奥利奥通知图标颜色为灰色