我想在同步图表中显示工具提示。请看这个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-Option设置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/。我已亲切地接受了此帖子http://forum.highcharts.com/highcharts-usage/synchronize-chart-with-shared-tooltip-t33919/中链接的代码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句