gpt4 book ai didi

javascript - Highcharts 同步图表显示工具提示

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:07:20 29 4
gpt4 key购买 nike

我想在同步图表中显示工具提示。请看这个Jsfiddle

 $('#container').bind('mousemove touchmove touchstart', function(e) {
var chart,
point,
i,
event;

for (i = 0; i < Highcharts.charts.length; i = i + 1) {
chart = Highcharts.charts[i];
event = chart.pointer.normalize(e.originalEvent); // Find coordinates within the chart
point = chart.series[0].searchPoint(event, true); // Get the hovered point

if (point) {
point.onMouseOver(); // Show the hover marker
chart.tooltip.refresh(point); // Show the tooltip
chart.xAxis[0].drawCrosshair(event, point); // Show the crosshair
}
}
});

tooltip只能显示第一个系列,不能显示第二个系列,甚至鼠标悬停在第二个系列上。

enter image description here

请指教。

最佳答案

首先,您必须将工具提示选项 shared 设置为 true。然后你必须更新 mousemove touchmove touchstart-Eventhandler 来处理多个系列/点

$('#container').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
}
}
}
});

参见 http://jsfiddle.net/doc_snyder/51zdn0jz/6/为您更新的 fiddle 。我很乐意接受这篇文章中链接的代码 http://forum.highcharts.com/highcharts-usage/synchronize-chart-with-shared-tooltip-t33919/ .

关于javascript - Highcharts 同步图表显示工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36437297/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com